user722302
user722302

Reputation: 63

Git subtree push always fails

Trying to use git subtree to share common library files across multiple projects. Here's the problem I keep encountering.

1) Add subtree so "lib" subdirectory of my project is coming from lib-dk repository.

$ git subtree add --prefix=lib --squash [email protected]:dwknight/lib-dk.git master

2) Make changes to files in "lib"

3) commit changes to main project repo

$ git commit -am "update project"

4) push updates to main project repo

$ git push origin master

5) push changes in "lib" back to "lib-dk" repo

$ git subtree push --prefix=lib [email protected]:dwknight/lib-dk.git master
git push using:  [email protected]:dwknight/lib-dk.git master
To [email protected]:dwknight/lib-dk.git
 ! [rejected]        f455c24a79447c6e3fe1690f5709357b7f96828a -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:dwknight/lib-dk.git'
hint: Updates were rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

6) I get this rejection even if nothing has changed in the lib-dk repo. When I try a pull, it acts like something has but I'm able to update via the pull. Still the push continues to be rejected.

Upvotes: 4

Views: 1857

Answers (3)

Pavel Anpin
Pavel Anpin

Reputation: 44

If you used --squash when you added a subtree you have to do git subtree pull --prefix=prefix remote branch --squash before you push

Upvotes: 0

randomness2077
randomness2077

Reputation: 1139

You might need use git add -A . then git commit rather than git commit -am <message>

since -A in git-add would do:

   -A, --all, --no-ignore-removal
       Update the index not only where the working tree has a file matching <pathspec> but also where the
       index already has an entry. This adds, modifies, and removes index entries to match the working
       tree.

       If no <pathspec> is given when -A option is used, all files in the entire working tree are updated
       (old versions of Git used to limit the update to the current directory and its subdirectories).

on the other hand, the -a in git-commit would do (not much details be given by the man page):

   -a, --all
       Tell the command to automatically stage files that have been modified and deleted, but new files
       you have not told Git about are not affected.

this might be helpful. The author called git add -A . explicitly.

Upvotes: 0

Jeff Terrell Ph.D.
Jeff Terrell Ph.D.

Reputation: 2713

When I try this without the --squash option to git subtree add, it works. I think, as the commenter suggested, the --squash is fiddling with the history in an unhelpful way.

Upvotes: 2

Related Questions