Phil
Phil

Reputation: 2236

Git: how to git pull onto changed file

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.

Upvotes: 1

Views: 1534

Answers (3)

Eugen Konkov
Eugen Konkov

Reputation: 25133

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

Upvotes: 0

David Deutsch
David Deutsch

Reputation: 19025

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).

Upvotes: 1

CodeWizard
CodeWizard

Reputation: 142094

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

Upvotes: 1

Related Questions