156

Delete a local and a remote GIT branch – Aram Koukia

 6 years ago
source link: https://koukia.ca/delete-a-local-and-a-remote-git-branch-61df0b10d323?gi=f86dd7b7ac3f
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Delete a local and a remote GIT branch

1*zhYQt3quMouCIzJrROdUBQ.jpeg

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK