This is a short practice to git branching. Refer to Pro Git (2nd Edition). I appreciate Scott Chacon, Ben Straub, and numerous contributors for making this wonderful guide book.
Make a new branch 'testing'
git branch testing
Switch 'HEAD' to 'testing' or 'master'
git checkout testing
git checkout master
Merge -> (Conflicts -> Edit -> Add -> Commit)
Conflicts may happen or not.
When you try to merge a new branch 'testing' (added fn add
) into 'master' branch (added fn substract
).
Conflicts occured because src/main.rs
in 'testing' and 'master' have different functions with slightly different main
functions.
You decided to manually edit the src/main.rs
to contain both functions (add
and substract
) with modifications in main
function.
- Change HEAD to 'master' branch (default initial branch name).
git checkout master
- Merge (name the branch to be merged).
git merge testing
- If they conflict, you have the following two options:
- You may abort the merge.
git merge --abort
- Open the file with the conflicts and edit it manually.
<<<<<<<: this indicates the contents of 'master'
from ======= to >>>>>>>: indicates the contents of 'testing'
You should erase '<<<, ===, >>>' because they will be saved to a commit if you don't delete them.
- After editing the file, git add to the edited file.
git add src/main.rs
- If the conflicts were resolved, you can commit which finishes the merge process.
git commit (or use GUI such as Sourcetree)
- Check whether there are no merged branches (p. 80).
git branch --no-merged