18. Git branches and merge
Main steps
If necessary, install meld and diffuse tools:
sudo apt install meldOpen your project:
cd ~/workspace/JTM- Add, commit and push changes of your project to the tools.odo.lv (to be sure you have all your previous work on tools.odo.lv).
Add new entry to remote repository in your project:
git remote add upstream ssh://user@tools.odo.lv/home/git/JTM/where user is actual username for your own git repository
Pull branches branch1 and branch2 from upstream repository to branches into your repository:
git fetch upstream branch1:branch1
git fetch upstream branch2:branch2Check that your repository has three branches:
git branchreturns:
branch1
branch2
* master- Make two copies of your project, for example JTM-1 and JTM-2 as sibling projects in your workspace.
Check out branches in copies of the project:
cd ~/workspace/JTM-1
git checkout branch1
cd ~/workspace/JTM-2
git checkout branch2- Open meld, and compare content of your original project, e.g. JTM and JTM-1, copy and save missing parts of content into JTM project.
- Compare content of catbN.txt files in jtm.activity18 package between projects with master and/or branch1/branch2 branches.
- Merge content of all numbered filees catbN.txt into single catb.txt file
- Check that catb.txt file has proper content by running GitMergeTest1.java unit test.
Before you add, commit and push changes to tools.odo.lv, ensure you are working on master branch, e.g. command:
git branchreturns:
branch1
branch2
* master
Additional info
- A Visual Git Reference
- On undoing, fixing, or removing commits in git
- How to undo (almost) anything with Git