1

I occasionally get thrown by the behavior of git. As I understand what I did below, I took the current version of the branch "public" on the remote repository, and replaced everything I had with it. Nothing I was working on should still be there.

Then I pulled "public" from the remote repository again. Voila! Now I am one commit ahead, locally.

Can you tell me what happened?

[edit] People very properly asked me what version of git I am using. 2.1.4 I added a git --version to my code section below.

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git status
# On branch public
# Your branch is ahead of 'origin/public' by 1 commit.
#
nothing to commit (working directory clean)

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git reset --hard origin/public
HEAD is now at 30cdb42 Remove O/D from window display if 640px window.innerWidth or less

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git status
# On branch public
nothing to commit (working directory clean)

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git pull origin public
\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" get: -c: line 0: syntax error near unexpected token `('
\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" get: -c: line 0: `\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" get'
Username for 'https://github.com':
Password for 'https://rickhedin@github.com':
\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" store: -c: line 0: syntax error near unexpected token `('
\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" store: -c: line 0: `\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" store'
From https://github.com/gogoit/gogo_flightTracker
* branch            public     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Fast-forwarded public to 2e65060cef06715081e54f776e0f7269e8d65ba7.

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git status
# On branch public
# Your branch is ahead of 'origin/public' by 1 commit.
#
nothing to commit (working directory clean)

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$

rhedin@RHEDIN1-T430 /cygdrive/c/work/150502
$ git --version
git version 2.1.4
user2171796
  • 397
  • 2
  • 16
  • What version of git are you using? (It appears to be on Windows, and I don't know any of the specifics about Windows-ized git variants, but git's behavior with `pull` changed in git 1.8.4 so this probably matters to whoever *can* answer windows-specific items.) – torek May 02 '15 at 20:23
  • possible duplicate of ['git pull origin mybranch' leaves local mybranch N commits ahead of origin. Why?](http://stackoverflow.com/questions/1741143/git-pull-origin-mybranch-leaves-local-mybranch-n-commits-ahead-of-origin-why) – TimWolla May 02 '15 at 21:09

1 Answers1

1

git-pull - Fetch from and integrate with another repository or a local branch

In the simplest terms, git pull does a git fetch followed by a git merge.

You can do a git fetch at any time to update your remote-tracking branches under refs/remotes/<remote>/. This operation never changes any of your own local branches under refs/heads, 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).

A git pull is what you would do to bring a local branch up-to-date with its remote version, while also updating your other remote-tracking branches.

Scenario:

Assume the following history exists and the current branch is "master":

 A---B---C master on origin
     /
    D---E---F---G master
    ^
    origin/master in your repository

Then "git pull" will fetch and replay the changes from the remote master branch since it diverged from the local master (i.e., E) until its current commit (C) on top of master and record the result in a new commit along with the names of the two parent commits and a log message from the user describing the changes.

  A---B---C origin/master
 /         \
D---E---F---G---H master

Git documentations:

git-pull

git-fetch

git-merge

SantanuMajumdar
  • 886
  • 1
  • 5
  • 20
  • That's all correct and makes sense, *except*, he's apparently already done a fetch (via pull), then a `git reset --hard` to make his own branch match the one on origin. Then he does another `pull` which does another `fetch` which should be a no-op, followed by another `merge` which should also be a no-op. This assumes git version >= 1.8.4, though. – torek May 03 '15 at 21:40
  • CloudFreezer's answer is so detailed and clear that I upvoted it. (I think in your last diagram, you intend D to branch off of B, and C branches to H, not G.) However, I think Torek's comment is correct. I make my branch identical to the one on the remote repostory, and then do a series of no-ops. The result should be identical to the remote repository. – user2171796 May 04 '15 at 17:17
  • My git version is 2.1.4 . – user2171796 May 04 '15 at 17:19