Have you ever gone through a few sprints of work, created several local and remote branches and wondering how to get rid of them (both local and remote branches)?
Here some tips to do that:
Delete a Local GIT branch
To delete the local GIT branch we can try one of the following commands:
git branch -d branch_name
git branch -D branch_name
as you can see above, we have 2 different argument, one with ‘d’ and one with ‘D’.
The
-d
option stands for --delete
, which would delete the local branch, only if you have already pushed and merged it with your remote branches.
The
-D
option stands for --delete --force
, which deletes the branch regardless of its push and merge status, so be careful using this one!Delete a remote GIT branch
To delete a remote branch you can use the following command:
git push <remote_name> --delete <branch_name>
Alternatively, there is this other following option too, which might be just a bit hard to remember:
$ git push <remote_name> :<branch_name>
These top options can also be used if you want to delete a “tag”.
Push to remote branch and delete
If you ever want to push your local branch to remote and delete your local, you can use
git push
with the -d
option as an alias for --delete
.
0 comments:
Post a Comment