![git create branch from origin git create branch from origin](https://imgs.developpaper.com/imgs/2671698998-5cac02ffb9d35_articlex.png)
(note that it is 'test' not 'origin/test') to perform magical DWIM-mery and create local branch 'test' for you, for which upstream would be remote-tracking branch 'origin/test'. Sidenote: With modern Git (>= 1.6.6), you are able to use just git checkout test If there there are multiple remote repositories configured it becomes a bit longer git checkout -b test /test To checkout out with only a single remote repository: git checkout test Git switch was added in Git 2.23, prior to this git checkout was used to switch branches.
#Git create branch from origin how to#
I also created the image below for you to share the differences, look at how to fetch works, and also how it's different to pull: With the remote branches in hand, you now need to check out the branch you are interested in with -c to create a new local branch: $ git switch -c test origin/testįor more information about using git switch: $ man git-switch In the case where multiple remote repositories exist, the remote repository needs to be explicitly named.Īs before, start by fetching the latest remote changes: $ git fetch origin In this case Git is guessing (can be disabled with -no-guess) that you are trying to checkout and track the remote branch with the same name. This is done with the Git command switch (since Git 2.23) by giving it the name of the remote branch (minus the remote name): $ git switch test To work on a branch you need to create a local branch from it. The branches that start with remotes/* can be thought of as read only copies of the remote branches. You can see the branches available for checkout with: $ git branch -v -a This will fetch all of the remote branches for you. In both cases, start by fetching from the remote repository to make sure you have all the latest changes downloaded. Updated for Git 2.23: For older versions, see the section at the end. The reason for this is that for the single remote case, some of the commands can be simplified as there is less ambiguity.
![git create branch from origin git create branch from origin](http://joelabrahamsson.com/PageFiles/215/1658_1992.jpg)
The answer has been split depending on whether there is one remote repository configured or multiple.