Skip to main content

Posts

Showing posts from March, 2019

Quick Trip: Rename Current branch in Git

I love to use Powershell and post-git module for day to day work with git. Sometimes, I have to rename my branches and I have this quick way to do to it. I love to write shortcuts in PowerShell's Profile to save time. Add this function in Powershell Profile.ps1: function RenameLocalBranch { param ( $ NewName ) $ currentBranch = git rev - parse -- abbrev - ref HEAD git branch - m $ NewName git push origin : $ currentBranch $ NewName git push origin - u $ NewName } save the profile.ps1 and open a new go to repo path call the function and give it a new branch name, it should update local and remote branch for you. here is the successful output: C:\Repos\proj [ name1 ≡ ] > RenameLocalBranch name2 Total 0 ( delta 0 ) , reused 0 ( delta 0 ) To https: // xxxxxxxxx.visualstudio.com / _git / xxxxxxxxxx - [ deleted ] name1 * [ new branch ] name2 -> name2 Everything up - to - date Branch ' name2