4

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 git@bitbucket.org: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 git@bitbucket.org:dwknight/lib-dk.git master
git push using:  git@bitbucket.org:dwknight/lib-dk.git master
To git@bitbucket.org:dwknight/lib-dk.git
 ! [rejected]        f455c24a79447c6e3fe1690f5709357b7f96828a -> master (non-fast-forward)
error: failed to push some refs to 'git@bitbucket.org: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.

user722302
  • 63
  • 5
  • 1
    I have no experience using the `subtree` command but the `--squash` operation looks like a `rebase` option. What does it do? If it's modifying the branch history somehow then that could cause this problem. – asm Feb 11 '13 at 16:22

3 Answers3

2

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.

Jeff Terrell Ph.D.
  • 2,563
  • 26
  • 39
0

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.

randomness2077
  • 1,119
  • 2
  • 13
  • 25
0

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