Skip to content
Snippets Groups Projects
Verified Commit 08505cd8 authored by Georgiana Mania's avatar Georgiana Mania Committed by Lukas Kluft
Browse files

add branches content

parent 46edd24c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment