Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble merging upstream changes back into my branch

I'm running into conflicts while trying to merge upstream changes back into my branch and I'm not sure how to resolve them.

I created my own fork. I cloned it. I made changes to the branch on my fork, committed, and pushed. But then the main fork updated, and I tried to update my own fork by merging upstream in like so:

$ cd repo-name $ git remote add upstream git://github.com/username/repo-name.git $ git fetch upstream $ git merge upstream/master 

The merge says that there's some problem with a file and auto-merging doesn't work. It tells me to fix it myself and re-merge. So I actually went to the (upstream) repository on GitHub of the main fork and copied all the code of the new file into the file on my fork, and tried to merge again. Then, git gives me this error:

fatal: 'merge' is not possible because you have unmerged files. Please, fix them up in the work tree, and then use 'git add/rm ' as appropriate to mark resolution and make a commit, or use 'git commit -a'.

Is there some argument I'm leaving out? Am I doing something stupid? What does it mean by "unmerged files?" Isn't the whole point of merging to merge files? Do I have to commit my changes before I merge?

like image 857
anonymous Avatar asked Apr 24 '11 20:04

anonymous


People also ask

How do I merge branch and upstream branch?

You basically just want to push b2 from the remote upstream to the branch b1 from the remote origin . So, you can git fetch to get that b2 branch locally as a tracking branch, and then push it to b1 on the remote origin .

Can't merge branch already up to date?

The message “Already up-to-date” means that all the changes from the branch you're trying to merge have already been merged to the branch you're currently on. More specifically it means that the branch you're trying to merge is a parent of your current branch.


2 Answers

What you are seeing means that automatic merge could not resolve the conflicts in the files. You need to resolve these conflicts manually. Run git mergetool or git gui.

like image 76
Šimon Tóth Avatar answered Sep 22 '22 23:09

Šimon Tóth


The "git merge" command tries to incorporate changes from another branch onto the present branch. If the merge is clean, meaning no conflicts, it will commit. Since your merge did have conflicts, it didn't commit. You need to resolve the conflict.

Pulling the copy from the upstream repo is one way to do that - by accepting the upstream repo's version. You can do that within git using "git checkout --theirs conflicting_file.txt"

Editing the file to get it into the shape you want is another way.

Once it's fixed, you need to add using "git add conflicting_file.txt" then commit. Then your working copy is clean and ready for more hacking. Good luck.

like image 40
cbare Avatar answered Sep 20 '22 23:09

cbare