Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Succinct way to create a tracking branch with Git

Tags:

git

bash

shell

Today I had to work with a remote branch called origin/}__test_syntax_error_in_simpack_settings. I wanted to create a tracking branch for it.

I had to type:

git branch }__test_syntax_error_in_simpack_settings origin/}__test_syntax_error_in_simpack_settings

I didn't have autocompletion on the first argument, only on the second. I don't like typing. Is there a faster way to do this? The main barrier is having to type the name of the new local tracking branch. Is there a way to tell Git, "create a tracking branch with the same name as origin/whatever?"

like image 963
Ram Rachum Avatar asked Apr 10 '11 21:04

Ram Rachum


People also ask

How do I create a remote tracking branch?

To create a new local branch based on a remote branch, use the "-track" option in the branch command. You can also do this by using the "checkout" command. If you want your local branch to have the same name as the remote branch, you only need to specify the name of the remote branch.

What are tracking branches and how you can setup one?

Checking out a local branch from a remote branch automatically creates what is called a tracking branch. Tracking branches are local branches that have a direct relationship to a remote branch. If you're on a tracking branch and type git push , Git automatically knows which server and branch to push to.

How do I create a new branch in git?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

What is track remote branch?

Remote-tracking branches are references to the state of remote branches. They're local references that you can't move; Git moves them for you whenever you do any network communication, to make sure they accurately represent the state of the remote repository.


2 Answers

git checkout -t -b whatever origin/whatever

or short

git checkout -t origin/whatever

Something to read: http://git-scm.com/docs/git-checkout

like image 152
KingCrunch Avatar answered Oct 12 '22 21:10

KingCrunch


I'd do this in bash:

git branch {,origin/}}__test_syntax_error_in_simpack_settings

Sidenote: you seem to have very unusual branch names that might create problems in shells unless properly escaped. Consider renaming your branches, to save yourself some typing and problems the easy way (the lowhanging fruit :))

like image 37
sehe Avatar answered Oct 12 '22 22:10

sehe