Remote Branches 2
(these posts are part of the material I cover in my devops course)
Create a demo repository
- Create a new demo repository in github and clone twice:
1cd ../../a/demo/
2git clone <your demo repository url>
3cd ../../b/demo/
4git clone <your demo repository url>
Create basic feature1 branch (same in both places)
- Create a feature1 branch in a and add something in it, then push.
1git checkout -b feature1
2echo hello > feature1.txt
3git add feature1.txt
4git commit -m "first commit in feature1 in a"
5git push --set-upstream origin feature1
- Verify that the branch was created in github, then get everything locally:
1cd ../../b/demo/
2git fetch
3git branch -a
4git branch feature1 origin/feature1
5git checkout feature1
6ls
(note that you could use pull to do the same)
Create the problem
- We want to demonstrate 2 programmers, working on the same branch, creating different features:
One is creating file2.txt, the other is creating file3.txt. - Go to a, create a new file, commit and push to github:
1cd ../../a/demo/
2echo hello > file2.txt
3git add file2.txt
4git commit -m "adding file2.txt to feature1 in a"
5git push
- Go to b, create a file, add, commit BUT DO NOT PUSH. Instead, fetch:
1cd ../../b/demo/
2echo hello > file3.txt
3git add file3.txt
4git commit -m "adding file3.txt to feature1 in b"
5git fetch
Looking at the changes in b
- A git status will show me the following:
1git status
2On branch feature1
3Your branch and 'origin/feature1' have diverged,
4and have 1 and 1 different commits each, respectively.
5 (use "git pull" to merge the remote branch into yours)
6
7nothing to commit, working tree clean
- Using git pull and editing the comment I merged the missing commit into b:
1git pull
- but this is not the end of it.
Doing git status again will show the problem:
Now b has information that is not updated to a (and to github).
A git push will solve this.
Looking at the changes in a
- The only thing left to do is in a local repository
- Do git fetch first to see, them git pull to merge