How do I synchronize master and origin/master using egit in eclipse?

11,206

Solution 1

Going by the relevant part of egit's documentation you can either:

  • click the "Add all branches spec" button, to push all of your local branches to ones with the same name in the remote repository, or
  • (the much safer option) just select master under both "Source ref" and "Destination ref" to only push your master branch

The remote-tracking branch origin/master is usually updated by git fetch (which is part of what git pull does), but with command line git, the remote-tracking branch is also updated on a successful push to the branch in the remote repository that's being tracked. It's possible that Egit, being based one of the pure Java implementations of git, JGit, rather than the command-line tools, doesn't update origin/master on a successful push in the same way. If that's the case, you can just do a fetch to update origin/master.


Update: It seems that this is a known bug in EGit (not the underlying JGit) - the bug report is here:

Solution 2

An update to this, I was using eclipse Helios, and I've upgraded to Indigo, with the latest version of egit, and the fix appears to be active, as I'm no longer having to pull after a push.

Share:
11,206
Mark Fisher
Author by

Mark Fisher

Kotlin developer and general system's dogsbody. #SOreadytohelp

Updated on June 22, 2022

Comments

  • Mark Fisher
    Mark Fisher almost 2 years

    I created a local git repository, and I push changes from it to a gitosis remote that I created with

    git init my_git
    git remote add origin git@server:my_git
    ... various adds and commits
    git push origin master:refs/heads/master
    

    Now, I edit and commit changes locally in eclipse, and when I commit, I see (using qgit) that it moves my master branch to that version.

    However, it also shows me that origin/master is at the previous version.

    git status on command line shows me everything is up to date:

    $ git status
    # On branch master
    nothing to commit (working directory clean)
    

    I can see the differences in versions with

    git diff origin/master
    

    If i do git push on my command line, then qgit shows me the origin/master branch is now at same place as my master.

    I can't work out how to configure the "remote / push" or "remote / configure push to upstream" dialog in eclipse to do the same thing as a command line git push to move the origin/master to the same level as the master.

    I always have to do the command line push to make the origin/master come up to the same place as master.

    Q1. Can anyone tell me how to do this in eclipse?

    Q2. What is the command line version of git push doing that the eclipse version doesn't do?

    Q3. Are my assumptions that master is my local HEAD pointer and origin/master is the remote server's view of the current HEAD correct?

  • Mark Fisher
    Mark Fisher over 12 years
    Excellent, the fetch did the trick. I think I understand why I have to fetch locally move the origin/master now, would this be a feature or a bug? I'd have expected to locally know where the remote master is if i was the one who just pushed a change to it, the fact i have to ask for it in a second step seems odd, and the command line is doing what I'd more naturally expect to happen.
  • Mark Longair
    Mark Longair over 12 years
    Yes, I'd expect the same, and I would call it a bug. In fact, I've just found this in the bug tracker: bugs.eclipse.org/bugs/show_bug.cgi?id=317411
  • Cromax
    Cromax about 10 years
    Hmm, I use Kepler and have local repo "L1" and also remote bare repo "R1" on another disk partition. Besides I made a bare clone "P" of R on a pendrive. On another computer I made a clone "R2" of P and then checkout out project form R2 into Eclipse using repo "L2". It basically server to exchange changes between two computers with help of pendrive and having bare backups on both computers. It looks like this: