90

With GitHub for Windows, you can "publish" a branch, and then "sync" that branch to GitHub.

enter image description here

Is the sync basically a git pull and git push? Or is there more to it? If I wanted to do the exact same steps as "sync" from the command line, what should I do?

(It's not Open Source, or I'd just read that.)

Jay Bazuzi
  • 45,157
  • 15
  • 111
  • 168

4 Answers4

53

Sync does git pull --rebase and then if there are local changes, it does git push.

From here: http://haacked.com/archive/2012/05/21/introducing-github-for-windows.aspx#87318

Matt Rix
  • 844
  • 7
  • 10
45

Since the above answer was more than two years ago, an updated answer to this question is: due to some bugs with rebase, the "sync" button does not do git pull --rebase anymore. Instead, it does git pull which will do merge if there are conflicts, according to this release notes (see release 1.3.0).

The link above is not available at this time. Here is the new release notes.

Ethan Yang
  • 862
  • 9
  • 20
  • 2
    Actually, that's not completely true. ONLY if a rebase doesn't work, it tries to do a merge. – Joris Meys Mar 17 '15 at 13:42
  • The release notes link is broken. – skolima Jan 13 '16 at 10:11
  • 2
    @JorisMeys I'm not sure your statement is true. In my experience, if there are *any* commits ahead of mine on remote, it will create a merge commit, even when it could do a rebase. – Jerad Rose Dec 15 '16 at 05:40
  • @JeradRose When I wrote my comment we were at Github Desktop v. 2.x, and we're at 3.3 by now :-) But you're right, I've noticed the same. – Joris Meys Dec 16 '16 at 09:52
17

"Sync" would be any actions necessary to have your local branch match your remote branch. If your local branch had commits that your remote branch didn't, then "sync" would push your branch. If the remote branch was ahead of your local branch, then "sync" would pull first (specifically, git pull --rebase, as was explained by Phil Haack). "Sync" is just a shortcut to getting the local and remote to mirror each other.

From the GitHub site:

The sync button turns the complex workflow of pulling and pushing into a single operation. It notifies you when there are new changes to pull down and lets you quickly share local changes.

redhotvengeance
  • 27,446
  • 10
  • 49
  • 54
  • It doesn't just pull - it does "git pull --rebase", which is a crucial difference. Also, the order you have is wrong, pull before push. – Andiih Feb 06 '13 at 09:49
  • 2
    @Andiih My language was generalized and not an ordered list of operations. The order was implied - notice I say "if the remote branch **was** ahead of your local branch"? My description was also a direct quote from the GitHub site. Regardless, Matt Rix's answer is more detailed, and deserves to be marked as the answer. I've made some small edits to clarify any confusion in my answer. – redhotvengeance Feb 06 '13 at 16:54
  • Does github sync also fetch upstream changes, in addition to origin. I.e. I haved f9rked a repo, and have a local clone of the fork, what I really want is the changes from upstream, not just origin – AaronLS Jul 27 '13 at 02:35
  • 1
    @AaronLS GitHub for Windows is only built to work with one remote right now, namely `origin`. To work with multiple remotes, you'll have to use the command line. Relevant info can be found [here](http://windows.github.com/help.html), under "Multiple Git remotes & non-GitHub remotes". – redhotvengeance Jul 27 '13 at 20:43
4

To add to @ethanyang's answer,

According to the alias configured in the gitconfig,

[alias]
...
sync = !git pull && git push
Community
  • 1
  • 1
  • 4
    Just out of curiosity, what does the ! mean in the above line? – Scott Romack Jul 14 '16 at 16:33
  • @ScottRomack it means that it's treated as a shell command: http://stackoverflow.com/questions/21083933/what-does-the-exclamation-mark-mean-in-git-config-alias – Nicolas Holthaus Dec 14 '16 at 18:44
  • Does GitHub Desktop have this alias already setup? If so, where is this config located? I didn't see this alias in my global `.gitconfig`. Or is this just an override of your own? – james Jan 18 '17 at 14:09