Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lecture materials
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marius Rixen
lecture materials
Commits
08505cd8
Verified
Commit
08505cd8
authored
1 year ago
by
Georgiana Mania
Committed by
Lukas Kluft
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
add branches content
parent
46edd24c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lectures/02-Git/slides.qmd
+157
-7
157 additions, 7 deletions
lectures/02-Git/slides.qmd
with
157 additions
and
7 deletions
lectures/02-Git/slides.qmd
+
157
−
7
View file @
08505cd8
...
...
@@ -23,14 +23,164 @@ author: "Lukas, Georgiana, Theresa, Tobi"
## Branches
(local repo - 5 slide - Georgiana)
* are versions of the code identified with a name (besides existing hash)
* are used to encapsulate the changes required for a new feature or a bugfix
* allow incremental development without impacting the `main` branch
* why use a branch?
* create/delete local branch
* rebase branch
* git add after editing a conflicting file - go through the text file
* merge branch into main
* stop lecture: do exercises
---
### Create a branch
```bash
# check the branches before creating a new one
git branch
* master
# create a new branch
git branch b1
# check the branches after adding a new branch
git branch
b1
* master
```
---
### Switch branches
```bash
# check the branches to see the current branch
git branch
b1
* master
# switch to the new branch
git checkout b1
# check the branches to see the current branch
git branch
* b1
master
```
---
### Rename a branch
```bash
# check the branches before rename
git branch
* b1
master
# rename current branch
git branch -m feature-new-sorting-algo
# check the branches after rename
git branch
* feature-new-sorting-algo
master
```
---
### Compare branches
```bash
git diff master..feature-new-sorting-algo
diff --git a/test.txt b/test.txt
index faab00e..f4ecce0 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
-this is a test.
+this is a test in a branch.
```
---
### Rebase a branch
```bash
# make changes in two branches
...
# rebase branch feature-new-sorting-algo on main
git rebase master
CONFLICT (content): Merge conflict in test.txt
error: could not apply 2ce7874... modify in branch
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 2ce7874... modify in branch
```
---
### Rebase a branch - edit conflicts
```bash
# view and edit the conflicting file
<<<<<<< HEAD
this is a test in master branch.
=======
this is a test in a branch.
>>>>>>> 2ce7874 (modify in branch)
# fix the conflict and continue the rebase
git add test.txt
git rebase --continue
[detached HEAD 3699a57] modify in branch
1 file changed, 1 insertion(+), 1 deletion(-)
Successfully rebased and updated refs/heads/feature-new-sorting-algo.
```
---
### Merge a branch
```bash
# move to destination branch
git checkout master
# merge source branch into destination branch
git merge feature-new-sorting-algo
Updating c3f5771..3699a57
Fast-forward
test.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
```
---
### Delete a branch
```bash
# check current branches
git branch
feature-new-sorting-algo
* master
# delete a branch
git branch -d feature-new-sorting-algo
# check branches after delete
git branch
* master
```
---
### Exercise time!
1. create a branch
2. rename the branch
3. make changes in both branches (`master` and the new one)
4. merge/rebase the new branch on master
5. check the log for the master branch
6. delete the new branch
---
## Best practices
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment