Git Commands for branch removing, renaming

Remove a branch locally:

To remove a branch locally the command is:

$ git branch -D <branch-name>

Rename a branch:

Rename your local branch. If you are on the branch you want to rename:

     $ git branch -m <new-name>

Delete the old-name remote branch and push the new-name local branch:

     $ git push origin :old-name new-name

Reset the upstream branch for the new-name local branch  Switch to the branch and then:

     $ git push origin -u new-name.

*Refer my old post for switching between branches

Remove branches that are not in remote:

You might have some branches locally that other members of your team have remote it remote. To get rid of those branches run:

     $ git remote prune origin

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s