Reputation: 13868
I'm often working with cloned repos, having an "origin" (my) and "upstream" (original source). I'm always cloning the "origin" repo from github for working on it and create PRs and from time to time need to pull from "upstream" to sync with the latest changes going on there.
After git clone <origin uri>
I can do
git push/pull
without specifying the branch since its already tracked; however doing this on the other remote
git pull upstream
when e.g. on master
branch I would like git to actually do
git pull upstream master
instead of:
You asked to pull from the remote 'upstream', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
I understand I can configure the tracking remote but I'd like to know if this can be automatic as long as branch names are identical.
Upvotes: 2
Views: 1462
Reputation: 24068
You can use below config, so whenever you checkout a new branch from remote, it will be automatically tracked, without needing you to setup tracking with --set-upstream-to
or --track
git config --global branch.autosetupmerge true
Upvotes: 1
Reputation: 3931
Just use --track
or --set-upstream-to(-u)
:
$ git branch --track master upstream/master
For the current branch:
$ git branch -u upstream/master
$ git branch --set-upstream-to=upstream/master
This'll assign the remote-tracking branch upstream/master
to your master
branch so that it's automatically fetched from in the next git pull
invocation.
From the man page:
-t, --track
When creating a new branch, set up branch.<name>.remote and branch.<name>.merge
configuration entries to mark the start-point branch as "upstream" from the new
branch. This configuration will tell git to show the relationship between the
two branches in git status and git branch -v. Furthermore, it directs git pull
without arguments to pull from the upstream when the new branch is checked out.
-u <upstream>, --set-upstream-to=<upstream>
Set up <branchname>'s tracking information so <upstream> is considered
<branchname>'s upstream branch. If no <branchname> is specified, then it defaults
to the current branch.
Upvotes: 0
Reputation: 500
You asked to pull from the remote 'upstream', but did not specify a branch. Because this is not the default configured remote for your current branch, you must specify a branch on the command line.
Looking at the message, the first thing is as you haven't configured upstream
as your default remote. So, first, you need to set it as the default remote like:
git config branch.branch_name.remote upstream
Now, you need to specify a branch from where you want to fetch the commits. You can specify that by running
git config branch.branch_name.merge refs/heads/branch_name
Hope it helps.
Upvotes: 0