Checkout "
MyBranch
" before deleting {OldBranch}
. It makes "MyBranch
" current/working branch.$ git checkout {MyBranch}Delete local "
MyBranch
". This is the safest option for deleting a local branch since branch doesn't get deleted if there is any unmerged changes exist.$ git branch -d {OldBranch}This is for force delete. It deletes the local branch with any existing unmerged changes. IMPORTANT: It can make you cry if you don't pay attention!
$ git branch -D {OldBranch}It deletes the remote branch and easy to remember.
$ git push {remote_name} --delete {OldBranch}Following command also to delete the remote branch.
$ git push {remote_name} :{OldBranch}Once we are done deleting remote branch, we can prune to get rid of remote tracking branches by executing any of the following commands.
$ git remote prune origin
$ git fetch origin --prune
$ git fetch origin -pOnce we are done deleting remote branch, we need to execute one of the following commands on other machine to remove obsolete tracking branches.
$ git fetch --all --prune
$ git fetch -a -pThis command lists branches that can be deleted/pruned on the local.
$ git remote prune origin --dry-runExecute this command to see a list of all your references in the repository.
$ git for-each-refExecute any of these commands to see just remote-tracking branches.
$ git branch --remotes
$ git branch -rExecute any of these commands to see both local and remote tracking branches.
$ git branch --all
$ git branch -a
TIP:
Run this command to delete all branches on remote that are already merged into master
.$ git branch -r --merged | grep -v master | sed 's/origin\///' | xargs
-n 1 git push --delete origin
Check out Git Branches.
No comments:
Post a Comment