The same way you can set the default repository and branch to push to, you can set defaults for git pull
too.
The master branch has a default set automatically when you clone the repository the first time, but branches don’t have these unless you specify manually. We’ve already seen the command to specify upstream branches manually when pushing. The same command applies here too:
1 |
git branch --set-upstream-to=origin/<branch> testing |
Here testing
is the local branch and origin/<branch>
is the remote branch. I can skip testing
if I am already checked out to that branch locally. And I can skip the =
sign between the switch and remote name. Also, -u
can be used as a shorter alternative to --set-upstream-to
.
1 |
git branch -u origin/<branch> |
Here’s what the command actually does:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# the repository config file - before PS> cat .\.git\config [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly [remote "origin"] url = git@github.com:rakheshster/PS-AppMgmt.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master # switch to the branch I want ... PS> git checkout testing Switched to branch 'testing' # ... and specify its upstream PS> git branch --set-upstream-to origin/testing Branch testing set up to track remote branch testing from origin. # the repository config file - after. notice the new entries. PS> cat .\.git\config [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly [remote "origin"] url = git@github.com:rakheshster/PS-AppMgmt.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [branch "testing"] remote = origin merge = refs/heads/testing |