Reputation: 2039
I have a git repository containing an application, and I want to use a subdir of that repo to update a shared library repository. I can fetch the library repo, commit an update, but I cannot make it push that commit back to the remote. It should be a fast-forward, but it says it is not. What am I doing wrong?
$ git remote add lib goertzen@minerva:/pub/shared_git_repositories/lib.git
$ git fetch
From minerva:/pub/shared_git_repositories/lib
* [new branch] master -> lib/master
$ git checkout -b libmaster lib/master
Branch libmaster set up to track remote branch master from lib.
Switched to a new branch 'libmaster'
$ git merge --squash -s subtree -X theirs master
Auto-merging lib.yaml
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested
$ git commit -m "blah blah blah"
[libmaster 4949ef3] blah blah blah
1 files changed, 148 insertions(+), 95 deletions(-)
$ git push lib
To goertzen@minerva:/pub/shared_git_repositories/lib.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'goertzen@minerva:/pub/shared_git_repositories/lib.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
$ git pull
Already up-to-date.
$ git log --graph --all --full-history --branches --decorate
* commit 4949ef3181c21d85340b9fb16af5f9c2c58e75ae (HEAD, libmaster)
| Author: <snip>
| Date: Tue Mar 8 15:25:03 2011 -0600
|
| minitransfer changes
|
* commit e2dca9e2bcd28d09a455e9cc662f7eb630a0adc2 (lib/master)
Author: <snip>
Date: Thu Feb 24 10:54:31 2011 -0600
initial commit of shared lib repo
* commit b70bde69e5c4ddb079d06d7310d415fa89764b95 (origin/master, origin/HEAD, master)
| Author: <snip>
| Date: Fri Mar 4 15:41:05 2011 -0600
|
| fix typo
|
* commit cc64b565fbb88729e16314f76867ab24c37bfc47
| Author: <snip>
| Date: Fri Mar 4 15:38:59 2011 -0600
|
...
I can replace the squashed subtree merge with a trivial edit, and I still have the same issues.
Upvotes: 1
Views: 1975
Reputation: 2039
It turns out "git push lib" was actually trying to push libmaster to origin/master instead of lib/master (I experimented on some sacrificial repos). When I spelled it all out in detail like this...
git push lib libmaster:master
...it worked.
I would of course like to be able to push without having to spell it out in detail. This leaves me wondering if I brought lib into the repo in an odd way, or if I need to configure the branch somehow. I have some reading to do...
Upvotes: 7