Git, Merging from Remote Branch
I did this on Bash on Windows 7 (64bit) against my github account.
I tried to push my change to github, and found it's not possible.
[sourcecode language="bash"]
$ git push -u origin master
[/sourcecode]
Enter passphrase for key ....:
To git@github.com:andrewchaa/JonSkeetCSharp4Examples.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:andrewchaa/JonSkeetCSharp4Examples.git
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
So, I need to merge the change. I remembered I committed some code last night at home.
[sourcecode language="bash"]
$ git fetch origin
[/sourcecode]
Then
[sourcecode language="bash"]
$ git checkout --track -b originmaster origin/master
[/sourcecode]
Branch originmaster set up to track remote branch master from origin. Switched to a new branch 'originmaster'
Now you check out your master branch (local)
[sourcecode language="bash"]
$ git checkout master
[/sourcecode]
Switched to branch 'master'
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commit(s) each, respectively.
And also checkout (get latest in TFS terms) originmaster
[sourcecode language="bash"]
$ git checkout originmaster
[/sourcecode]
Switched to branch 'originmaster'
Now point to master back to start merge
[sourcecode language="bash"]
$ git checkout master
[/sourcecode]
Switched to branch 'master'
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commit(s) each, respectively.
In the mean time, I had to set up beyondcompare for git.
[sourcecode language="bash"]
$ git config --global diff.tool bc3
$ git config --global difftool.bc3.path "C:/Program Files (x86)/Beyond Compare 3/bcomp.exe"
$ git config --global merge.tool bc3
$ git config --global mergetool.bc3.path "C:/Program Files (x86)/Beyond Compare 3/bcomp.exe"
[/sourcecode]
You can see on which branch you are
[sourcecode language="bash"]
$ git branch
[/sourcecode]
* master
originmaster
Now, finally merge
[sourcecode language="bash"]
$ git merge originmaster
[/sourcecode]
Merge made by recursive.
Examples/ArrayExample.cs | 41 ++++++++++++++++++++++++++++++++++++++++
Examples/CollectionsExample.cs | 40 +++++++++++++++++++++++++++++++++++++++
Examples/Examples.csproj | 2 +
3 files changed, 83 insertions(+), 0 deletions(-)
create mode 100644 Examples/ArrayExample.cs
create mode 100644 Examples/CollectionsExample.cs
Then, it's done.
[sourcecode language="bash"]
$ git status
[/sourcecode]
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)
Then, push back to githum
[sourcecode language="bash"]
$ git push -u origin master
[/sourcecode]
Enter passphrase for key '.....':
Counting objects: 12, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 1.31 KiB, done.
Total 7 (delta 4), reused 0 (delta 0)
To git@github.com:andrewchaa/JonSkeetCSharp4Examples.git
cf1a6ea..59b280f master -> master
Branch master set up to track remote branch master from origin.
To summarise, I use the following commands
[sourcecode language="bash"]
$ git fetch origin
$ git checkout --track -b originmaster origin/master
$ git checkout master
$ git checkout originmaster
$ git checkout master
$ git config --global diff.tool bc3
$ git config --global difftool.bc3.path "C:/Program Files (x86)/Beyond Compare 3/bcomp.exe"
$ git config --global merge.tool bc3
$ git config --global mergetool.bc3.path "C:/Program Files (x86)/Beyond Compare 3/bcomp.exe"
$ git branch
$ git merge originmaster
$ git status
$ git push -u origin master
[/sourcecode]
Comments