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
answersand switch to it - Make sure you are on branch
answers, notmaster. Usegit statusandgit branchto 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.txtand 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
packagethat don't belong to the branchmaster?
- Switch back to the branch
master. - Create a new file
7.txtand commit it to the repository - Look at the commit history with branches. See how the branch
answersbranches out frommaster - Merge the branch
answersintomaster - Look at the commit history with branches. See how the branch
answersmerges back intomaster, but the pointer ofanswersis 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 --allto push information of all branches. - Push all changes to the remote using
git push --all git branchcan accept many arguments that we didn't look at in the lecture. You can usegit branch --no-mergeto see branches that have not been merged into the current branch orgit branch --mergeto see branches that have been merged- Use
git branch --mergeto 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