I have a larger git repository (A) that shares a certain amount of code with another project (B) of mine. To make maintenance easier, I decided to have a third repository with the common code (C) which will then be used via git subtree
.
I prepared everything in A (putting the common code in folder "sub") and used the procedure described in Detach (move) subdirectory into separate Git repository to create C
Now that I have C with just a few commits, I wanted to put it back into A, folder sub. I used the approach described in http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html which worked insofar as all commits for the subfolder were now duplicated. I didn't quite mind this, however now I am stuck with no idea how to continue working with this subdirectory.
I made additional changes in A/sub which I want to push to C. As described in git subtree push changes back to subtree project I used
git subtree split --prefix sub -b split-branch
to create a branch with just the subtree. This takes a bit of time, but finishes successfully. Doing
git checkout split-branch
git push remote-c master
gives me
failed to push some refs to "remote-c"
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
but a git pull remote-c master
says I'm already up-to-date.
How do I resolve this situation?
EDIT1: I tried to reproduce the problem with a small test script. Executing this script:
( cd testC; git init --bare )
( cd testA; git init )
cd testA
git remote add C ../testC
mkdir sub
echo subFile1 > sub/subFile1
echo subFile2 > sub/subFile2
git add sub
git commit -m "adding files"
echo FileA > fileA
echo FileB > fileB
git add fileA fileB
git commit -m "add root level files"
# extract subtree and push to C
git subtree split -P sub -b split-branch
git push C split-branch:master
# try to make an update in C
git checkout -b cmaster C/master
echo subFile2new > subFile2
git commit subFile2 -m "updated #2 in C"
git push
This results in
To ../testC
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '../testC'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration
hint: variable to 'current' or 'upstream' to push only the current branch.