Domanda

I have a feeling this has been asked before but I can't find it in SO.
When is the right moment to push a topic branch to origin?

I am asking this because we have a workflow at work where we end up git push --force quite often. The workflow is to rebase onto master when our topic branch has fallen behind, but because we push our topic branches early and often, that means that this rebase onto master requires a force push to publish the new, rebased topic branch.

Now I am thinking that the root reason to need this ugly and dangerous force is because we are pushing the topic branch often (one reason being to backup your work, another to have your work accessible in case you miss work or something), maybe this is wrong?? so I am wondering, when is the best moment to push a branch since normally once it's pushed, a rebase basically becomes forbidden, yet we still do it.
Should the topic branch push only happen once the branch is ready to be merged? but then you risk losing your work if your hard disk dies or having your work trapped in your machine

If it's important, we are following a pull-request model like github (BUT without forking) where the merge of topic to master happens on a repo manager on a central server, hence why we need to push topic branches

È stato utile?

Soluzione

Don't think of --force as meaning "You shouldn't do this." Think of it more as meaning "You shouldn't do this unless you know what you're doing."

You do know what you're doing, and you're not causing anyone any trouble, so --force isn't really a problem.

Remember that Git commits originate on someone else's machine before they reach the remote repo. So by pushing with --force, you're not likely to be destroying work, because someone else already had that work on his/her machine.

I guess it comes down to this: You have the idea that --force is ugly and dangerous. But why? Sure, it shouldn't be taken lightly. But it's a tool in your toolbox, and you know how to use it correctly. You could avoid ever incorporating the changes from master until your topic branch is done (or at least nearly done). Or you could each push to a private repo, which would still let you back up without having to worry about anyone else when force-pushing.

But if using --force works, why worry about it?

Altri suggerimenti

That depends on your particular workflow. I keep my origins completely up to date at all time (mostly for my own use, few external onlookers, next to none interested in day-to-day or experimental changes/topic branches). You might want to restrict publication of experimental branches until they are ripe (or not liable to be axed anymore ;-), or even never publish them.

If you work together with a group of people, you should agree on (at least rough) policy on this.

You might want to search for suggestions on git workflows, there are several around. Not that you'll need to follow any of them, but the discussions on when to use each (and why) should clear up the matter.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top