

We can then push the merges back to the remote repositorys version of the branch. One final word of advice: there is no substitute for communication. This tutorial introduces the stash command of git, which allows you to easily move the changes to the correct branch. Then checkout the branch of interest and merge from the updated local main. A typical scenario is that you pushed the branch but did not make a PR out of it you were just pushing as backup. Combined with common sense, it's the way to go. But it does ensure that you are the first person to do anything new with the branch, so what you are doing is relatively safe. This doesn't ensure that no one else has fetched the branch (they probably have, since every fetch fetches everything) or that no one else has made a local copy of the branch. It is like taking a "lease" on the ref without explicitly locking it, and the remote ref is updated only if the "lease" is still valid. As the docs say: If the remote ref still points at the commit you specified, you can be sure that no other people did anything to the ref.

This will prevent you from pushing if someone else has actually done anything to change this branch. Well, when you do, use -force-with-lease. If the remote ref still points at the commit you specified, you can be sure that no other people did anything to the ref. To push, you will have to push with force. For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull (1) and other commands. This will prevent you from pushing if someone else has actually done anything to change this branch. First of all, when pushing for the first time, do: git push -u origin hp1:team/hp1. To push, you will have to push with force. In recent years, Git has provided a way to help thread this little needle. As you rightly infer, the question is whether the branch is truly shared remotely, not merely whether it has been pushed. We are often told not to change the history of a branch we've already pushed to the remote.
