Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine your default remote git repository?

How can I see the default remote repository set on my Pycharm? I want to know when I type git push without specifying the repository name, which of my remote repository is going to be updated, assuming that I have added multiple remote repository with different alias names.

like image 784
Infintyyy Avatar asked Sep 13 '25 03:09

Infintyyy


1 Answers

To get the default remote to push to, you can use %(push:remotename) in format:

git for-each-ref --format='%(push:remotename)' $(git symbolic-ref HEAD)

To get the default remote to pull from, you can use %(upstream:remotename) in format:

git for-each-ref --format='%(upstream:remotename)' $(git symbolic-ref HEAD)

You can also use git branch --list but somehow it's slightly slower (0.1s vs 0.2s on my machine).


(original answer below)

It seems like git ls-remote --get-url is the command. It prints URL instead of the remote name, but it was sufficient in my case. git ls-remote assumes the default remote if you don't provide one, so you can get the default remote URL with it. The doc was not very clear about the usage though.

Edit: Turns out it's the default URL to pull from, not push to. Better options above.

like image 160
snipsnipsnip Avatar answered Sep 14 '25 20:09

snipsnipsnip