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

Rebasing two branches Git

Rebasing is necessary in Git if your team is working on multiple branches. To merge code from remote branch to your working branch these commands are necessary:

First checkout to your remote branch and fetch all files

$ git checkout -b remote-branch

$ git fetch

Then give rebase from your working branch

$ git checkout working-branch

$ git rebase -i remote-branch

Then see the conflicts using

$ git status

Resolve all the conflicts then do

$ git add .

$ git rebase --continue