Changing a Git branch that's tracking a remote

Some git commands and output that shows one of the commands in action and the result of running them

Having done some work against a local branch that's associated with a remote for a certain piece of work I've decided I want to keep the work (it's given me some proof-of-concept ideas) but start again on the actual task at hand. Keeping the current branch with all my commits but being able to "reset" back to the branch as it is on the server is the ideal outcome, which I've noted how to do below.

As with almost anything else Git related, there's a lot of places where this answer already exists I'm sure, but for my own reference (and perhaps as someone else might find this as a result of searching and find use for it) here are the steps to take a local branch that's tracking a remote one, rename it and stop it tracking the remote. 

With the branch in question being current (which will show in green with an asterisk next to it when running git branch from the console), run the following commands:

git branch -m new_name_for_branch
git branch --unset-upstream

The first command renames the branch and the second command, well, unsets the upstream branch associated with the local branch.

About Rob

I've been interested in computing since the day my Dad purchased his first business PC (an Amstrad PC 1640 for anyone interested) which introduced me to MS-DOS batch programming and BASIC.

My skillset has matured somewhat since then, which you'll probably see from the posts here. You can read a bit more about me on the about page of the site, or check out some of the other posts on my areas of interest.

No Comments

Add a Comment