Git: which is the default configured remote for a branch?
"Get" commands
For a branch named branch_name
, read it out with this:
git config branch.branch_name.remote
Examples:
# main branch
git config branch.main.remote
# master branch
git config branch.master.remote
Sample output:
origin
"Set" commands
Change the default remote for a branch like this:
# for branch "branch_name", change the default remote to "remote_name"
git config branch.branch_name.remote remote_name
# Examples:
# main -> origin
git config branch.main.remote origin
# main -> upstream
git config branch.main.remote upstream
There is no output when running the set commands just above.
See all remotes
See all of your remote names and their URLs with:
git remote -v
The -v
means "verbose".
Example run and output:
wiki_copy_demo.wiki$ git remote -v
origin [email protected]:ElectricRCAircraftGuy/wiki_copy_demo.wiki.git (fetch)
origin [email protected]:ElectricRCAircraftGuy/wiki_copy_demo.wiki.git (push)
upstream https://github.com/nicolargo/glances.wiki.git (fetch)
upstream https://github.com/nicolargo/glances.wiki.git (push)
git config
general details
You can programmatically read out any given branch's locally-stored remote-tracking remote name via git config branch.branch_name.remote
.
Assume that you have a branch named main
and its remote it tracks is set to origin
. In that case, your .git/config
file will contain this, among other things:
[branch "main"]
remote = origin
merge = refs/heads/main
Running this:
git config branch.main.remote
...will therefore read out that configuration setting and return the value of remote
, which is origin
.
And running this:
git config branch.main.remote upstream
...will change the value of remote
from origin
(its previous value) to upstream
.
You can use these patterns to programmatically read or write any git config variable, even ones you invent or make up yourself.
Example: this command: git config --global blametool.editor subl
adds these lines to the bottom of your global ~/.gitconfig
file:
[blametool]
editor = subl
And you can read out that variable value, subl
, with: git config blametool.editor
.
That's how I set a blametool for my git blametool
script.
git pull hub master
? – Galoot