views:

150

answers:

1

I have a Git repository with a branch that hardly ever changes (nobody else is contributing to it). It is basically the master branch with some code and files stripped out. Having this branch around makes it easy for me to package up a leaner version of my project without having to strip out the code and files manually every time.

I have been using git rebase to keep this branch up to date with the master but I always get this warning when I try to push the branch after rebasing:

To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

I then use git push --force and it works but I feel like this is probably bad practice. I want to keep this branch "in sync" with the master quickly and easily. Is there a better way of handling this task?

Update

See this topic for a full explanation and solution:

http://stackoverflow.com/questions/559917/git-rebase-and-git-push-non-fast-forward-why-use

+2  A: 

The trick is:

  • when you rebase your "template" branch, you change its history (different SHA1), meaning any push won't be a fast-forward one (there a no "new SHA1" to add, but an entirely new set of SHA1 to replace)
  • you then push that branch to a non-bare repo (which is now by default prevented)

It is a bad practice:

  • if other people depend on fetching that branch (which is not the case here)
  • if you depend on the content of the working tree of the remote repo to which you push to (because that content, if set to represent the template branch, could be not in sync with the actual template branch you just pushed)

If those two points are not an issue, you could go on.
But the (or a more) "proper" way to deal with that would be to have an intermediate bare repo (on the remote server) to push to, and then fetching/pulling the template branch from that bare repo to other server where you need that template project.

VonC
Thanks Von, I appreciate it. Just to clarify your last point. I would set the origin of the "template" branch to a new bare repo or the remote server (I am using Github) and push it there. What command would I need to execute to pull from the bare repo into my remote branch of the existing repo?
m1755