Steve Crane
Steve Crane

Reputation: 4440

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

Upvotes: 1

Views: 63

Answers (1)

knittl
knittl

Reputation: 265595

Simply provide --no-track to checkout:

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

Upvotes: 3

Related Questions