slackline
slackline

Reputation: 2417

Git origin is behind head

I've two branches on a git repo of my dotfiles, master and kimura and a remote setup on GitLab. If I checkout either branch and git push I'm told I'm up-to-date...

$ git checkout master
Already on 'master'
$ git push
Everything up-to-date
$ git checkout kimura
Switched to branch 'kimura'
$ git push
Everything up-to-date

I've made changes on branch kimura and submitted and merged pull-requests to master then merged the kimura with master using...

$ git checkout kimura
Switched to branch 'kimura'
$ git merge origin/master
Already up to date.

However I've powerline prompts (under ZSH) and both show that I've commits waiting to be pushed and when I look at the history it shows the origin for both branches are behind the HEAD...

*   ef61530 - (HEAD -> kimura) Resolving conflict to merge master into kimura (2019-01-26) <slackline>
|\  
| * 1ece19c - (origin/master) Reinstated sourcing of virtualenvwrapper.sh on work host (2019-01-18) <slackline>
| *   80efc48 - Merge branch 'kimura' into 'master' (2018-12-17) <nshephard>
| |\  
* | | f32a089 - tweaking virtualenvwrapper.sh path for new host (2019-01-24) <slackline>
* | | d2ccb42 - Tweaking specifics for work machine. (2019-01-24) <slackline>
* | | 13fc696 - Updates to a few files (2019-01-24) <slackline>
* | | a453190 - Added gnupg to link section (2019-01-23) <slackline>
* | | c7da4ac - Added todo task and display of warnings at end of setup (2019-01-23) <slackline>
* | | 07f313b - Added gnupg (2019-01-23) <slackline>
* | | 20cf7f8 - Copying sample code from James (2019-01-23) <slackline>
* | | 4edf7b5 - updated path for /mnt/personal (2019-01-12) <slackline>
* | | 0b61635 - adding work_laptop profile (2018-12-19) <slackline>
* | | 71c7d3f - Adding config/.config/.pycodestyle (2018-12-18) <slackline>
| |/  
|/|   
* | 8ac383a - (origin/kimura) Starting off yapf config (2018-12-17) <slackline>
|/  
*   3d6aac6 - Merge branch 'master' of gitlab.com:nshephard/dotfiles into kimura (2018-12-10) <slackline>

I'm unsure how to get the origin on either branch to align with HEAD and would appreciate any suggestions/pointers.

EDIT :

On @Tim Biegeleisen suggestion I've tried the following...

$ git fetch origin
From gitlab.com:nshephard/dotfiles
 * branch            master     -> FETCH_HEAD
$ git checkout kimura
Switched to branch 'kimura'
$ git merge origin/master
Already up to date.

I've then tried merging the kimura branch directly with master...

$ git checkout origin/master                                                                                                                                                                                                                                                                           
error: Your local changes to the following files would be overwritten by checkout:                                                                                                                                                                                                                                              
    gnupg/.gnupg/random_seed                                                                                                                                                                                                                                                                                                
Please commit your changes or stash them before you switch branches.                                                                                                                                                                                                                                                            
Aborting                                                                                                                                                                                                                                                                                                                        
$ git stash                                                                                                                                                                                                                                                                                            
Saved working directory and index state WIP on kimura: 8464bcc Merge 

branch 'kimura' into 'master'

$ git checkout origin/master                                                                                                                                                                                                                                                                           
Note: checking out 'origin/master'.                                                                                                                                                                                                                                                                                             

You are in 'detached HEAD' state. You can look around, make experimental                                                                                                                                                                                                                                                        
changes and commit them, and you can discard any commits you make in this                                                                                                                                                                                                                                                       
state without impacting any branches by performing another checkout.                                                                                                                                                                                                                                                            

If you want to create a new branch to retain commits you create, you may                                                                                                                                                                                                                                                        
do so (now or later) by using -b with the checkout command again. 
Example:                                                                                                                                                                                                                                                      

  git checkout -b <new-branch-name>                                                                                                                                                                                                                                                                                             

HEAD is now at 1ece19c Reinstated sourcing of virtualenvwrapper.sh on work host

...and on branch master origin still isn't quite up-to-date with HEAD as I'm now in a detached state having gone back to origin and having commits that are not yet merged...

* 1ece19c - (HEAD, origin/master) Reinstated sourcing of virtualenvwrapper.sh on work host (Fri Jan 18 10:52:17 2019 +0000) <Neil Shephard>
*   80efc48 - Merge branch 'kimura' into 'master' (Mon Dec 17 18:10:50 2018 +0000) <nshephard>
|\
| * 8ac383a - (origin/kimura) Starting off yapf config (Mon Dec 17 17:15:42 2018 +0000) <slackline>
|/
*   3d6aac6 - Merge branch 'master' of gitlab.com:nshephard/dotfiles into kimura (Mon Dec 10 10:41:47 2018 +0000) <slackline>
|\
| *   2e0a40e - Resolving conflicts in zsh/.zshrc (Mon Dec 10 10:35:45 2018 +0000) <Neil Shephard>
| |\
| | *   1b0a018 - Merge branch 'kimura' into 'master' (Thu Dec 6 10:22:25 2018 +0000) <nshephard>
| | |\
| * | | a6f3350 - Removing line that calls virtualenvwrapper on work computer (Mon Dec 10 10:32:47 2018 +0000) <Neil Shephard>
| |/ /
| * | fefb0b0 - Commenting out $PATH (Mon Dec 3 13:38:33 2018 +0000) <Neil Shephard>
| * |   2597385 - Merge branch 'kimura' into 'master' (Wed Nov 14 09:57:56 2018 +0000) <nshephard>
| |\ \
* | | | 69d1599 - Added port forwarding for mongodb to ds1 config (Fri Dec 7 10:33:52 2018 +0000) <slackline>
| |_|/
|/| |

...and am stumped again as to how to merge everything and bring origin to be inline with HEAD.

EDIT 2 :

As requested by @torek ...

$ git rev-parse --abbrev-ref master@{upstream}
fatal: upstream branch 'refs/heads/master' not stored as a remote-tracking branch

My git config looks like...

[email protected]
user.name=slackline
push.default=simple
credential.helper=cache
pack.window=0
pack.windowmemory=100m
pack.packsizelimit=100m
pack.threads=1
color.ui=auto
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
[email protected]:nshephard/dotfiles.git
[email protected]:nshephard/dotfiles.git
remote.origin.push=+refs/heads/*:refs/heads/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.master.pushremote=origin
submodule.tmux/.tmux/plugins/tpm.url=https://github.com/tmux-plugins/tpm
submodule.tmux/.tmux/plugins/tpm.active=true
submodule.oh-my-zsh/.oh-my-zsh.url=https://github.com/robbyrussell/oh-my-zsh
submodule.oh-my-zsh/.oh-my-zsh.active=true
submodule.emacs/[email protected]:nshephard/emacs.git
submodule.emacs/emacs.active=true
submodule.emacs/[email protected]:nshephard/emacs.git
submodule.emacs/.emacs.d.active=true
submodule.fonts.url=https://github.com/powerline/fonts
submodule.fonts.active=true
branch.kimura.remote=origin
branch.kimura.merge=refs/heads/kimura
branch.kimura.fetch=+refs/heads/*:refs/heads/*

Current log/graph looks like...

*   564630f - (HEAD -> kimura, master) Merge branch 'kimura' into 'master' (Mon Jan 28 16:01:30 2019 +0000) <nshephard>
|\  
| * c6c75ba - Updating to use RSA keys as seahorse doesn't like ed25519 keys (Mon Jan 28 16:00:35 2019 +0000) <slackline>
|/  
*   8464bcc - Merge branch 'kimura' into 'master' (Sat Jan 26 09:32:05 2019 +0000) <nshephard>
|\  
| *   ef61530 - Resolving conflict to merge master into kimura (Sat Jan 26 09:30:54 2019 +0000) <slackline>
| |\  
| | * 1ece19c - (origin/master) Reinstated sourcing of virtualenvwrapper.sh on work host (Fri Jan 18 10:52:17 2019 +0000) <Neil Shephard>
| | *   80efc48 - Merge branch 'kimura' into 'master' (Mon Dec 17 18:10:50 2018 +0000) <nshephard>
| | |\  
* | | \   6138abc - Merge branch 'kimura' into 'master' (Thu Jan 24 11:39:35 2019 +0000) <nshephard>
|\ \ \ \  
| |/ / /  
| * | | f32a089 - tweaking virtualenvwrapper.sh path for new host (Thu Jan 24 11:39:04 2019 +0000) <slackline>
| * | | d2ccb42 - Tweaking specifics for work machine. (Thu Jan 24 11:37:48 2019 +0000) <slackline>
| * | | 13fc696 - Updates to a few files (Thu Jan 24 07:09:41 2019 +0000) <slackline>
| * | | a453190 - Added gnupg to link section (Wed Jan 23 13:08:29 2019 +0000) <slackline>
| * | | c7da4ac - Added todo task and display of warnings at end of setup (Wed Jan 23 11:01:08 2019 +0000) <slackline>
| * | | 07f313b - Added gnupg (Wed Jan 23 10:58:22 2019 +0000) <slackline>
| * | | 20cf7f8 - Copying sample code from James Ridgway https://github.com/jamesridgway/dotfiles/blob/master/setup (Wed Jan 23 10:57:32 2019 +0000) <slackline>
| * | | 4edf7b5 - updated path for /mnt/personal (Sat Jan 12 07:55:45 2019 +0000) <slackline>
| * | | 0b61635 - adding work_laptop profile (Wed Dec 19 12:34:16 2018 +0000) <slackline>
| * | | 71c7d3f - Adding config/.config/.pycodestyle (Tue Dec 18 16:32:52 2018 +0000) <slackline>
| | |/  
| |/|   
| * | 8ac383a - (origin/kimura) Starting off yapf config (Mon Dec 17 17:15:42 2018 +0000) <slackline>
| |/  
| *   3d6aac6 - Merge branch 'master' of gitlab.com:nshephard/dotfiles into kimura (Mon Dec 10 10:41:47 2018 +0000) <slackline>

Upvotes: 2

Views: 2487

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522731

I never saw you doing a git fetch or git pull, so most likely your local branches are out of sync with the remote. The following should work:

git fetch origin
git checkout kimura
git merge origin/master

The git fetch call should update your local tracking branch origin/master with the latest changes from the remote. You could also merge with master directly, assuming you had pulled that branch:

git checkout master
git pull origin master
git checkout kimura
git merge master

Upvotes: 4

Related Questions