I'm on a my master branch which is a perfect clean (but git presents it that it is ahead of origin/master by 14 commits). When I try to pull a different branch from origin (Eagle) git wants me to merge a few files.
This is not what I expect: When pulling a branch it should import the remote branch and leave the current HEAD untouched and not bother me with merge conflicts. In my perception The 2 branches live apart but peacefully from eachother, without any conflicts. But this perception holds no longer.
What causes these conflicts and how to restore 2 different branches without merging?
Below a transcript of the git session on commandline.
HEAD is now at 34e47ab ISS-652 misspelled MockBean in test/ApplicationContext
build@jenkins/p-project/workspace> git status
# On branch master
# Your branch is ahead of 'origin/master' by 14 commits.
#
nothing to commit (working directory clean)
build@jenkins/p-project/workspace> git log -5
.. Same as origin
build@jenkins/p-project/workspace> git push origin master
Everything up-to-date
build@jenkins/p-project/workspace> git status
# On branch master
# Your branch is ahead of 'origin/master' by 14 commits.
#
nothing to commit (working directory clean)
build@jenkins/p-project/workspace> git pull origin Eagle
From ssh://[email protected]:7999/hig/p-project-container
* branch Eagle -> FETCH_HEAD
Auto-merged pom.xml
CONFLICT (content): Merge conflict in pom.xml
Auto-merged p-project-client/pom.xml
CONFLICT (content): Merge conflict in p-project-client/pom.xml
Auto-merged p-project-container-conf/pom.xml
CONFLICT (content): Merge conflict in p-project-container-conf/pom.xml
Auto-merged p-project-container-conf/src/main/resources/dpl/P-Project_Container.xml
CONFLICT (content): Merge conflict in p-project-container-conf/src/main/resources/dpl/P-Project_Container.xml
Auto-merged p-project-container-conf/src/main/resources/was/P-Project_Container-app-env.cfg
Auto-merged p-project-container-ear/pom.xml
CONFLICT (content): Merge conflict in p-project-container-ear/pom.xml
Auto-merged p-project-container-filters/pom.xml
CONFLICT (content): Merge conflict in p-project-container-filters/pom.xml
Auto-merged p-project-container-ldap/pom.xml
CONFLICT (content): Merge conflict in p-project-container-ldap/pom.xml
Auto-merged p-project-container-tomcattest/pom.xml
CONFLICT (content): Merge conflict in p-project-container-tomcattest/pom.xml
Auto-merged p-project-container-web/pom.xml
CONFLICT (content): Merge conflict in p-project-container-web/pom.xml
Automatic merge failed; fix conflicts and then commit the result.
build@jenkins/p-project/workspace>
What git pull origin branch
does is that it fetches and merges the remote branch into your current local branch. So, the result of the above command is - to merge the remote branch eagle
into your local master.
I guess what you want is to create a new local independent branch which tracks the corresponding remote branch. You can do that with
git fetch
git checkout -b eagle --track origin/eagle
This will create a new separate local branch eagle
which would reflect the remote branch eagle
.
This local branch will be independent of your local master branch and keep your local master untouched.
You can do git status
and it will show Your branch is up-to-date with 'origin/eagle'.
and you can checkout master with git checkout master
and then doing a git status
will show ahead by 14 commits
.