What will happen if I delete a branch on my git repo and someone try to push a commit to it?
Just a simple question that might seems dumb but I’m not a git expert!
Let’s say I delete a branch in local and push my delete. The branch will no longer be on my git repository.
But what’ll happen if then another user try to push a commit to this branch.
Will an error happen or will the branch be created again?
2 Solutions collect form web for “What will happen if I delete a branch on my git repo and someone try to push a commit to it?”
I wasn’t sure, so I tested it out. It probably depends on permissions, but a new branch will be created in the target repository with the HEAD at the other user’s latest commit.
Note that your branch is still in your git repo, and the question “Git: Recover deleted (remote) branch” explain how to find it back.
That also confirm Explosion Pills’s answer: pushing a branch with the same name will re-create it on the upstream remote repo side with the new history.
Since the upstream repo doesn’t contain that branch (after you pushed the ref
:aBranch to delete it), said remote repo will create a new branch with the same name.