0

I have a repository set up on GitHub that I have set up to use to sync code between two PCs (home and work). Today I encountered a strange problem.

When I do a git fetch origin followed by git merge master, I get the message Already up-to date. That means both my local copy and the remote branch are mirror images, right? But the problem is some of the files are different in the two repositories, and it bothers me that there's nothing to commit (basically the remote repo is newer). To test it, when I did a git push origin master I get an error saying Updates were rejected because the tip of your current branch is behind.

The latter case is as it should be, but why am I not able to fetch those changes? Please note that I haven't tried git pull because I hear it's bad practice.

======== UPDATE ======

The output of git remote show origin is as follows (my remote is named as todoparrot):

* remote todoparrot
  Fetch URL: https://github.com/ankush981/todoparrot.git
  Push  URL: https://github.com/ankush981/todoparrot.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (local out of date)
ankush981
  • 5,159
  • 8
  • 51
  • 96
  • I don't really use the command line, so I'm not entirely sure how it all works, but if there aren't any local changes, then wouldn't there be nothing to merge? i.e. wouldn't pull be the only thing that works? – Mike Kellogg Aug 14 '15 at 18:38
  • 1
    Can you edit to add the results of `git remote show origin`, redacted if necessary? It sounds like your tracking may not be set up consistently. – Jeff Bowman Aug 14 '15 at 18:39
  • @MikeKellogg Not really. Pull means fetch + merge. And there *is* something to merge as the remote is newer and definitely has changes I can see when I browse the files. – ankush981 Aug 14 '15 at 18:42

1 Answers1

1

When you run git merge master, then it assumes you're merging from master into your current branch (also master), which is always unhelpfully "Already up-to-date".

To merge manually, you would run:

git merge origin/master

Furthermore, compared to output here, it looks like your local branch doesn't have an "upstream branch" set; git remote show origin demonstrates this by saying you don't have it "configured for git pull". It's probably a good idea to set one, so git can infer the right behavior without you having to spell everything out.

To set your upstream branch, run:

git branch --set-upstream=origin/master

At that point, you can just manually merge with:

git merge

...because from the git merge docs:

If no commit is given from the command line, merge the remote-tracking branches that the current branch is configured to use as its upstream. See also the configuration section of this manual page.


As a personal aside, I don't think git pull is bad practice, except that it's tempting to learn git pull and never learn what's going on behind the scenes. It's one of those shortcuts best used after you've taken the long way a few times. This article offers a similar opinion.

Community
  • 1
  • 1
Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251