Practice 4: Branching
By the end of this practice, you will know how to
- List, create, delete branches in Git
- Switch branches in Git
- Merge branches in git
Branching
- Fork (see last practice) the repository for this practice: https://github.com/Stopa/cse-prac4-branching
- Clone your fork of the repository to your computer
- Create a new branch
answers
and switch to it - Make sure you are on branch
answers
, notmaster
. Usegit status
andgit branch
to see where you are - Use the commands introduced in the lectures or any third-party software to inspect the repository. Find answers to the following questions; write them to a file
answers.txt
and commit the file to the repository:- What branches exist in this project?
- What branch has been merged into master?
- How many commits (in total) does the repository have?
- What commits belong to branch
package
that don't belong to the branchmaster
?
- Switch back to the branch
master
. - Create a new file
7.txt
and commit it to the repository - Look at the commit history with branches. See how the branch
answers
branches out frommaster
- Merge the branch
answers
intomaster
- Look at the commit history with branches. See how the branch
answers
merges back intomaster
, but the pointer ofanswers
is still on a separate branch. - By default, Git pushes only the current branch. You need to push a branch explicitly, as shown in the lecture. Or you can use
git push --all
to push information of all branches. - Push all changes to the remote using
git push --all
git branch
can accept many arguments that we didn't look at in the lecture. You can usegit branch --no-merge
to see branches that have not been merged into the current branch orgit branch --merge
to see branches that have been merged- Use
git branch --merge
to see what branches have been merged into master and delete them. When deleting branches, remember that Git doesn't delete remote branches. usegit push origin --delete <branch>
to delete the required branches also in the remote