I have ended up with a git repository in a state I don't know how to handle, and I need some help with understanding a) what's going on, how and why the repository is in this state, and b) how I should react to it. Basically, when pulling from the remote, I end up ahead of the remote, even if I reset all changes and try again.
This is what I've done:
I have forked a git repository, cloned the upstream version (which I don't have write access to) and then added my own fork to the list of remotes, so that git remote -v
shows the following:
$ git remote -v
mine [email protected]:tlycken/julia.git (fetch)
mine [email protected]:tlycken/julia.git (push)
origin git://github.com/JuliaLang/julia.git (fetch)
origin git://github.com/JuliaLang/julia.git (push)
I now want to make sure that my local version is up to date with everything in the upstream repo, so I run
$ git pull origin master
From git://github.com/JuliaLang/julia
* branch master -> FETCH_HEAD
Already up-to-date.
tlycken$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
This confuses me. Why is my branch ahead of origin master? I haven't changed anything.
To see if I could do something about it, I ran git lg
(an alias for git log --graph
with some prettyprint). The top of the output looks like this:
* 6912a42 - (HEAD, mine/master, master) Merge pull request #3052 from daviddelaat/linalgnumber (2013-05-10 11:23:09 -0700) <Viral B. Shah>
|\
| * 8116d51 - Use Number instead of Integer in some linalg operations (2013-05-10 19:12:45 +0200) <David de Laat>
* | 6cc1532 - Update .travis.yml configuration in the manual. (2013-05-10 21:41:59 +0530) <Viral B. Shah>
* | fa1e3fe - Update logdet. Close #3070. (2013-05-10 19:35:37 +0530) <Viral B. Shah>
* | a182f7f - (origin/master, origin/HEAD, mine/contrib-base) Merge branch 'master' of github.com:JuliaLang/julia (2013-05-10 03:10:38 -0400) <Jeff Bezanson>
Apparently, the HEAD's are in different positions. To make sure that I get the correct code in my local repository before I start branching out, I did git reset --hard origin/HEAD
to remove anything I was ahead, and then git pull origin master
to make sure I was up to date (i.e. didn't reset too far or something):
$ git pull origin master
From git://github.com/JuliaLang/julia
* branch master -> FETCH_HEAD
Updating a182f7f..6912a42
Fast-forward
base/linalg/dense.jl | 2 +-
base/linalg/factorization.jl | 44 ++++++++++++++++++++++----------------------
doc/manual/packages.rst | 3 +--
3 files changed, 24 insertions(+), 25 deletions(-)
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
and I'm back where I started.
What is going on here? What should I do to get to a state where my local master has the latest updates from upstream?
git pull
doesn't update your tracking refs (origin/
...) that keep track of where various remotes' HEAD
s are.
Run git fetch origin
and it'll update all of the origin/
... tracking refs and git status
will no longer think you're ahead.
git pull <remote> <branch>
is the equivalent of:
git fetch <remote> <branch>:FETCH_HEAD
git merge FETCH_HEAD
Because it explicitly specifies only the one branch to fetch, and fetches it into the special local ref FETCH_HEAD
, it doesn't update anything else locally - only FETCH_HEAD
and the branch you're pulling into.
Running git fetch <remote>
instead will update all of the refs associated with that remote repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With