Delete Git Branch

Git Branch

1. Checkout "MyBranch" before deleting {OldBranch}. It makes "MyBranch" current/working branch.
     $ git checkout {MyBranch}
2. 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}
3. 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}
4. It deletes the remote branch and easy to remember.
     $ git push {remote_name} --delete {OldBranch}
5. Following command also to delete the remote branch.
     $ git push {remote_name} :{OldBranch}
6. 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 -p
7. Once we are done deleting remote branch, we need to execute the following command on other machine to remove obsolete tracking branches.
     $ git fetch --all --prune 
8. Execute this command to see a list of all your references in the repository.
     $ git for-each-ref
9. Execute any of these commands to see just remote-tracking branches.
     $ git branch --remotes
     $ git branch -r
10. Execute 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

Grab The Button...

Grab the above button and add to your blog or website to get easy access to Virtual Species. Simply click the textbox, copy the code and paste where you want to see the button. That's it!