![]() ![]() and a remote tracking branch like origin/master.Note that Git 2.37 (Q3 2022) allows you to aumtomatically setup that remote tracking branch, with: git config -global toSetupRemote trueīut actually, once you establish an upstream branch relationship between: So origin/master is a remote tracking branch for master in the origin repo. There's no such concept of local tracking branches, only remote tracking branches. The SO question " Having a hard time understanding git-fetch" includes: Tracking branches are local branches that have a direct relationship to a remote branch (use "git pull" to merge the remote branch into yours) Your branch and 'origin/dev' have diverged,Īnd have 3 and 1 different commits each, respectively. (use "git push" to publish your local commits) Your branch is ahead of 'origin/master' by 1 commit. With a tracking branch, git status will tell you how far behind your tracking branch you are - useful to remind you that you haven't pushed your changes yet! It looks like this: $ git status Now, your local branch sf will automatically push to and pull from origin/serverfix. To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name: $ git checkout -b sf origin/serverfixīranch sf set up to track remote branch refs/remotes/origin/serverfix. If you have Git version 1.6.2 or later, you can also use the -track shorthand: $ git checkout -track origin/serverfixīranch serverfix set up to track remote branch refs/remotes/origin/serverfix. The simple case is the example you just saw, running git checkout -b /. However, you can set up other tracking branches if you wish - ones that don’t track branches on origin and don’t track the master branch. That’s why git push and git pull work out of the box with no other arguments. When you clone a repository, it generally automatically creates a master branch that tracks origin/master. Also, running git pull while on one of these branches fetches all the remote references and then automatically merges in the corresponding remote branch. If you’re on a tracking branch and type git push, Git automatically knows which server and branch to push to. Tracking branches are local branches that have a direct relationship to a remote branch. The ProGit book has a very good explanation:Ĭhecking out a local branch from a remote branch automatically creates what is called a tracking branch. I'm reading through " The Pragmatic Guide to Git" (great book, by the way), and they seem to suggest that tracking branches are a good thing and that after creating your first remote (origin, in this case), you should set up your master branch to be a tracking branch, but it unfortunately doesn't cover why a tracking branch is a good thing or what benefits you get by setting up your master branch to be a tracking branch of your origin repository.Ĭan someone please enlighten me (in English)? Unfortunately, being new to git and coming from SVN, that definition makes absolutely no sense to me. Can someone explain a "tracking branch" as it applies to git? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |