1

I changed a file in my testing repository and git push the change.

Now I want to git pull to my developement repo. However the developement repo also has a change in the same file...so I want to merge the 2 changes together.

Git merge doesn't work - not something we can merge

I ended up doing git checkout <file> to delete my changes and git pull then manually editing the changes back. But I would like to know if there is a better way to do this.

Phil
  • 2,176
  • 10
  • 33
  • 56

3 Answers3

1

Once your code is fully committed you can pull changes from the remote.

If you will have conflicts git will alert you about it and you will have to resolve them.

Sounds strange that you can't merge and you don't have conflicts and cant merge the files.

How to resolve it?

# checkout the 2 branches 
git checkout branch1
git checkout branch2

# now merge locally the 2 branches
git merge branch1
Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • I think "`merge branch1 into branch2`" would be a less-misleading comment. (And do you really need to checkout `branch1` first? I'm surprised that line is required). – RJFalconer Feb 16 '16 at 16:52
  • Its to be sure that you have them all locally. of course that if you worked on branch one and you pushed it from your machine its useless but its a general answer for all similar cases. – CodeWizard Feb 16 '16 at 16:54
  • Not related but what do you think about this git ascii-art? http://stackoverflow.com/questions/35400416/what-are-some-more-forceful-ways-than-a-gitignore-to-keep-files-out-of-a-repo/35400472#35400472 – CodeWizard Feb 16 '16 at 16:55
  • I needed to commit my changes before doing `git pull` to get the merge to work. I will accept this answer because the first 2 sentences told me the solution to my specific error/problem. The rest of it does not apply to me though and is more complicated than I need. – Phil Feb 16 '16 at 21:39
1

A git pull is a combination of a git fetch and a git merge, so if you had not undone your changes before the git pull, you would have automatically merged the changes.

That being said, it is odd that you got an error when doing git merge but not when doing git pull - unless you specified the remote and branch when you did git pull, but did not specify the remote tracking branch when you did git merge. If that is the case, you will want to associate your local branch with the remote tracking branch with git branch --set-upstream-to=origin/master master (replace master with whatever branch you want).

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
0

If you working directory is unclean you may stash this changes before pull and restore them after:

git stash
git pull
git stash pop

PS. if you supply more output from your commands I will supply more detailed response

Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158