![]() ![]() For example, you just cloned a repository and want to check out additional branches from the remote. And evidently, if your repository has only one remote, then you can just do git checkout after fetch and it will create a local branch for you. That is, git fetch followed by git checkout -b / does exactly the same as my initial answer. Thanks, Bash!Īlso as the answer in this similar Stack Overflow post shows, if you don't name the local branch in fetch, you can still create it when you check it out by using the -b flag. That is, I don't even have to name the local branch Bash automatically copies the name of the remote branch for me. īash is so smart it auto completes the first command if I tab after the first few letters of the remote branch. This is explained under options in the explanation of. where is the remote branch or source ref and is the as yet non-existent local branch or destination ref you want to track and which you probably want to name the same as the remote branch or source ref. If you want a local branch, use the -track option.įull details are here: 3.5 Git Branching - Remote Branches, Tracking Branches ![]() Note that with recent Git versions, this command will not create a local branch and will put you in a 'detached HEAD' state. track is shorthand for git checkout -b / where is origin in this case and is twice the same, daves_branch in this case.įor Git 1.5.6.5 you needed this: git checkout -track -b daves_branch origin/daves_branchįor Git 1.7.2.3 and higher, this is enough (it might have started earlier, but this is the earliest confirmation I could find quickly): git checkout daves_branch When you push your changes the remote branch will be updated.įor most recent versions of Git: git checkout -track origin/daves_branch The following command will create a local branch named daves_branch, tracking the remote branch origin/daves_branch. You need to create a local branch that tracks a remote branch. Note that if daves_branch doesn't exist locally you'll need to git fetch first before using switch. It will then also automatically set up remote branch tracking. Since you do not have the branch locally, this will automatically make switch look on the remote repo. If daves_branch exists on the remote repository, but not on your local branch, you can simply type: git switch daves_branch All of the information written below was accurate, but a new command, git switch has been added that simplifies the effort. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |