Branching
Why Branch?
Make mars.txt a pro/con list
No Change
No Change
branch
mars.txt
mars.txt
mars.txt
mars.txt
mars.txt
Master branch
New idea branch
you test your new idea on this branch
Everyone looks at this unchanged version
Branching
- create a branch called pro_con_list
- ask git which branch you are on
- switch to your new branch
git branch pro_con_list
git branch
git checkout pro_con_list
- Modify mars.txt to be a pro/con list
- save your changes
- View mars.txt on the pro_con_list branch
- View mars.txt on the master branch
Exercise 1
- Make sure you are on the master branch
- Create a new file called packing_list.txt with an item you want to bring to mars
-
- Is this visible on in your file system?
- Switch to the pro_con_list branch. Is it visible?
- Switch back to the master branch. Add and commit packing list
- Repeat 2.1 and 2.2. Why is the result different?
- Switch back to the master branch
- Create a new branch called wolfman_packing
- Switch to wolfman_packing and add an item to packing_list.txt. Add and commit packing_list.txt to the wolfman_packing branch
- Switch back to master. Is your new item on the packing list?
git branch branch_name
git checkout branch_name
git branch
Merging
add item to packing_list.txt
add item to packing_list.txt
no change
packing_list.txt
packing_list.txt
packing_list.txt
packing_list.txt
packing_list.txt
packing_list.txt
Combination of red and yellow files
Merging: No conflict
- Different lines modified
- Merge pro/con list into master
- Save merge commit message
- Check that you are on the master branch
- Look at mars.txt
- Delete branch if needed
- WARNING: you cannot recover branches once they've been deleted
git checkout master
git merge pro_con_list
git branch -D pro_con_list
Exercise 2
- view packing_list.txt on the master branch
- view packing_list.txt on wolf man_packing branch
- switch back to the master branch
- merge wolfman's packing list into the master packing list. DO NOT delete wolf man's branch
- Repeat #1 and 2
Merging w/Conflict
- The same line modified
- modify line 2 of mars.txt on the wolf man_packing branch
- add and commit
- checkout the master branch
- modify line 2 of mars.txt on the master branch
- add and commit
- merge wolfman_packing into master
- CONFLICT
git merge wolfman_packing
Resolving Conflicts
- How to resolve it
- open mars.txt
- Edit file until it looks they way you want it to look.
- Add and commit (you don't need the -m this time)
Text from master branch
Text from wolf man_packing branch
}
}
Exercise 3
- Modify the first line of packing_list.txt on the master branch
- add and commit
- Switch to the wolfman_packing branch
- Modify the first line of packing_list.txt on the wolfman_packing branch
- add and commit
- Merge the wolf man_packing branch into the master branch
- resolve conflicts
- add and commit
Resource: http://git-scm.com/book/en/
deck
By abostroem
deck
- 1,683