21. Git branches and merges
Review the presentation Version Control
Tasks
If necessary, install the meld compare and merge tool:
sudo apt install meldOpen your project:
cd ~/workspace/xxxxxxx- Add, commit, and push changes to your project to tools.odo.lv (to make sure you have everything saved on the server tools.odo.lv).
Add a new remote repository entry to your project:
git remote add upstream ssh://user@tools.odo.lv/home/git/JTM/where user is the actual username of your git repository
Pull branches branch1 and branch2 from the upstream repository into the same branches in your project:
git fetch upstream branch1:branch1
git fetch upstream branch2:branch2Check if your project has three branches:
git branchreturns:
branch1
branch2
* master- Create two copies of your project, for example xxxxx-1 and xxxxxx-2 as sibling projects in your workspace.
View branches in project copies:
cd ~/workspace/xxxxx-1
git checkout branch1
cd ~/workspace/xxxxx-2
git checkout branch2- Open meld and compare the contents of your original project, for example xxxxxx and xxxxx-1, copy and save the missing parts of the content in project xxxxx.
- Compare the contents of the catbN.txt files in the jtm.activity21 package between the projects with the master and/or branch1/branch2 branches.
- Merge the contents of all numbered files catbN.txt into a single catb.txt file.
- Verify that the file catb.txt has the correct contents by running the GitMergeTest1.java unit test.
Before add, commit, and push changes to the server tools.odo.lv, make sure you are working with the master branch, for example:
git branchreturns:
branch1
branch2
* master
More information
- A Visual Git Reference
- On undoing, fixing, or removing commits in git
- How to undo (almost) anything with Git