In Git, I sometimes work on long-running branches. I like to rebase on master from time to time to make merging easier when I'm ready.
After rebasing, I can't push a previously-pushed branch to a remote, because my branch's history no longer agrees with the remote's history of that branch. So I have to delete it first.
This is my current workflow:
git checkout my_branch
git rebase master
git push origin :my_branch # Delete remote version of the branch
git push origin my_branch # Push up my new version of history on this branch
Is there a single, atomic command that could replace the last two commands?
Instead of using the git branch command that you use for local branches, you can delete a remote branche with the git push command. Then you specify the name of the remote, which in most cases is origin . -d is the flag for deleting, an alias for --delete . remote_branch_name is the remote branch you want to delete.
To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .
Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.
If you are allowed to rewrite the remote branch, you can use git push --force my_remote my_branch
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With