eclipse git confusions: How to merge & push?
I can never seem to figure out how to use git. I just do random commands and it works eventually. This is what I usually do when I want to push:
Fetch from upstream
- Jenkins : actual and formal argument lists differ in length
- Getting “CHECKOUT can only be performed on a version resource” when trying to commit using Eclipse subversive plugin
- EGit “synchronize workspace” won't mark merge conflict as resolved
- .classpath and .project - check into version control or not?
- Eclipse Git Configuration System Settings is disabled
- Aptana 1.5 “svn: Error resolving case of”
Push to upstream
However, the above steps don’t work sometimes. For example, when I do fetch from upstream, my local branch doesn’t get updated.
How do I merge the remote branch into my local branch? Is there a difference between pull and fetch?
3 Solutions collect form web for “eclipse git confusions: How to merge & push?”
“git pull” is equivalent to “git fetch” followed by “git merge”
What you want to do is:
git commit -am "your message here"
This commits your current changes locally, and only locally. Now, assuming branch “foo”:
git pull origin foo
This does a “git fetch” followed by a “git merge”. Everything in this step is done to your local branch, and still has no effect on the remote branch. Depending on how your git is setup, you might need to specify the branch.
If you have a merge conflict, you will have to fix the files listed, then add them back:
git add path/to/resolved.file
When you are done, push everything you have from your local changes, to the remote server:
git push origin foo
If you pull before committing, that might cause your local branch to not be updated.
tl;dr, always commit before pulling!
Well to understand differences betwene git fetch and git pull look here.
In the simplest terms, “git pull” does a “git fetch” followed by a
You can do a “git fetch” at any time to update your local copy of a
remote branch. This operation never changes any of your own branches
and is safe to do without changing your working copy. I have even
heard of people running “git fetch” periodically in a cron job in the
background (although I wouldn’t recommend doing this).
Working with git in eclipse might be a little bit tricky, but if you understand git basics, you should cope with it. I recommend you to read one of git tutorials, so you will be able to understand basic git operations.
The first step to learn git: Don’t use egit.
Now, you are fetching and pulling from upstream. That makes me think that several people have write-access to the same repository, so we probably don’t want to be doing a whole lot of merges to complicate history. It would be best to do this. I’m assuming you have already committed a changes or a set of changes to your local
master branch that you want to place on the
upstream repository which has been pushed to by someone else while you were making your commits.
First, we fetch the new changes but don’t use them yet. This updates
upstream/master to the new head of the upstream
git fetch upstream master
Now, we need to pull in these changes. This command rewrites history, and we are assuming
that you have not published your changes anywhere yet.
git rebase upstream/master master
If you have published your changes, this messier command is the one you should use (do not use both, just use this one!)
git merge upstream/master master
Now, we can push:
git push upstream master
The first two steps can be shorted to
git pull --rebase and
git pull for the
merge versions respectively.
If you are already on the
master branch, most of those second arguments are superfluous but I wrote them in for clarity. Notably, giving a second argument to
git-merge will simply check out that branch before doing the operation. Supplying
push is only necessary if you don’t have the refs set up to automatically fetch and push master.