Is there a single git command to create a local branch from a remote branch that does not track the remote branch?


If I want to create a new local branch from remote branch release/A. I know I can do this

git checkout release/A
git checkout -b feature/A1

and I will have feature/A1 checked out and ready for changes.

But I grow tired of having to issue two commands to do this. I could make a script to do this but git has so many tricks I wondered if there might be a way to do this in one command. I tried

git checkout -b feature/A1 origin/release/A

and it does create local branch feature/A1 but also gives it a tracking branch against origin/release/A, which is not something I want. I will never update release/A directly; ultimately I would push feature/A1 to remote before issuing a pull request against release/A.

To clarify; is there a single command that does the same as the following two commands?

git checkout release/A
git checkout -b feature/A1


Simply provide --no-track to checkout:

git checkout -b --no-track feature/A1 origin/release/A

Answered By – knittl

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published