Short answer: git remote -v shows every remote with its URL, and git remote get-url origin prints just the URL of origin. To list the remote branches, run git fetch --prune and then git branch -r, or ask the server directly with git ls-remote --heads origin.
$ git remote -v
origin deploy@203.0.113.10:/srv/git/app.git (fetch)
origin deploy@203.0.113.10:/srv/git/app.git (push)
$ git remote get-url origin
deploy@203.0.113.10:/srv/git/app.git
$ git branch -r
origin/feature/login
origin/mainThe outputs on this page come from Git 2.39.5, the version in Debian 12, run on 9 November 2026 in throwaway repositories. The "server" is a bare repository on the same machine, reached through a stand-in for ssh that ran the server-side Git command locally, so the URLs look like a real VPS. 203.0.113.10 and git.example.com are documentation placeholders; use your own server or Git host.
Cheat sheet: git remote commands
| Task | Command |
|---|---|
| Show remotes and URLs | git remote -v |
| Print one remote's URL | git remote get-url origin |
| URL as stored in .git/config | git config --get remote.origin.url |
| Details: HEAD branch, tracked branches | git remote show origin |
| Remote branches known locally | git branch -r |
| Local and remote branches | git branch -a |
| Branches on the server right now | git ls-remote --heads origin |
| Drop branches deleted on the server | git fetch --prune |
| Add a remote | git remote add upstream URL |
| Rename a remote | git remote rename origin old-origin |
| Remove a remote | git remote remove upstream |
| Change the URL (HTTPS to SSH) | git remote set-url origin git@git.example.com:team/app.git |
Show the remote URL
Three commands answer "where does this repository push to", and they can differ in one case. With a URL rewrite rule such as url."git@git.example.com:".insteadOf https://git.example.com/ in your Git config, we got:
$ git remote -v
origin git@git.example.com:team/site.git (fetch)
origin git@git.example.com:team/site.git (push)
$ git remote get-url origin
git@git.example.com:team/site.git
$ git config --get remote.origin.url
https://git.example.com/team/site.gitgit remote -v and get-url show the URL Git will actually use, after rewrites; git config --get shows the text stored in .git/config. Without rewrite rules all three agree. get-url prints only the first URL unless you add --all, and --push asks for the push URL. In a repository without that remote, get-url fails with error: No such remote 'origin', while git config --get prints nothing and exits with 1, which is handy in scripts.
git remote show origin contacts the server and summarises everything at once:
* remote origin
Fetch URL: deploy@203.0.113.10:/srv/git/app.git
Push URL: deploy@203.0.113.10:/srv/git/app.git
HEAD branch: main
Remote branches:
feature/login tracked
main tracked
refs/remotes/origin/release/1.2 stale (use 'git remote prune' to remove)
Local branch configured for 'git pull':
main merges with remote main
Local ref configured for 'git push':
main pushes to main (up to date)Add -n to skip the network and use what the last fetch stored. The stale line is a branch someone deleted on the server that your clone still remembers, which leads to the next section.
List remote branches
git branch -r lists remote-tracking branches: your clone’s copy of the server’s branch list as of the last fetch or pull. After a colleague pushed two branches, our clone still showed only origin/main. git ls-remote asks the server instead and saw them at once:
$ git branch -r
origin/main
$ git ls-remote --heads origin
28f2fd0ea785fe6311e79bd05a20b3003f2b83f8 refs/heads/feature/login
1e83730b45ce9b58469413c6913ea1b373151b74 refs/heads/main
1e83730b45ce9b58469413c6913ea1b373151b74 refs/heads/release/1.2
$ git fetch
From 203.0.113.10:/srv/git/app
* [new branch] feature/login -> origin/feature/login
* [new branch] release/1.2 -> origin/release/1.2
$ git branch -a
* main
remotes/origin/feature/login
remotes/origin/main
remotes/origin/release/1.2The reverse also holds: a branch deleted on the server stays in git branch -r until you prune it. A plain git fetch kept origin/release/1.2; git fetch --prune removed it:
From 203.0.113.10:/srv/git/app
- [deleted] (none) -> origin/release/1.2git config --global fetch.prune truemakes every fetch and pull prune.git branch -r -vadds the last commit of each branch, andgit branch -r --list 'origin/feature/*'filters by name.git ls-remote --heads origin 'feature/*'filters on the server side. Git 2.46 renamed--headsto--branchesand keeps the old name as a deprecated synonym; Git 2.39 knows only--heads.
To work on one of those branches, git switch feature/login creates a local branch that tracks it; creating a Git branch covers that and pushing new branches, and renaming a branch covers renames on the remote.
Add, rename and remove a remote
git remote add upstream https://git.example.com/upstream/site.git
git remote rename origin fork
git remote remove upstream # same as: git remote rm upstreamrename also renames the remote-tracking branches and the upstream settings of your local branches; remove deletes them along with the remote. Neither touches anything on the server. The errors are short, and the exit code tells them apart in scripts:
| Message | When | Exit code |
|---|---|---|
error: remote origin already exists. | git remote add with a name in use; use set-url to change it | 3 |
error: No such remote: 'upstream' | remove or rename of a name that does not exist | 2 |
error: No such remote 'nosuch' | get-url or set-url of a name that does not exist | 2 |
fatal: 'origin' does not appear to be a git repository | git push origin main with no remote of that name | 128 |
fatal: No configured push destination. | Plain git push in a repository without remotes | 128 |
Change the remote URL from HTTPS to SSH
$ git remote set-url origin git@git.example.com:team/site.git
$ git remote -v
origin git@git.example.com:team/site.git (fetch)
origin git@git.example.com:team/site.git (push)set-url changes only the URL; branches, tracking and history stay as they are. The SSH URL comes in two spellings:
user@host:path/repo.git, the short form. It cannot carry a port.ssh://user@host:2222/srv/git/app.git, the long form, for SSH on another port. For that URL Git calledsshwith-o SendEnv=GIT_PROTOCOL -p 2222 deploy@203.0.113.10 git-upload-pack '/srv/git/app.git'. A host alias in ~/.ssh/config keeps the short form and sets port, user and key there.
Once the remote uses SSH, Git needs a key the server accepts. If the next fetch fails, the message comes from ssh, not Git: Permission denied (publickey) means the key is missing or not authorised, and Host key verification failed means known_hosts has no entry, or a different one, for that server.
Push to your own server: a bare repository over SSH
A VPS with SSH access is a complete Git server for a small team: no web interface, just a bare repository (one without a working tree) that you push to and clone from.
- 1Create the bare repository on the server
on the server sudo mkdir -p /srv/git sudo chown deploy: /srv/git git init --bare /srv/git/site.gitRun the last line as the SSH user, here
deploy, so pushes can write to it. - 2Add it as a remote and push
on your machine · example output $ git remote add production deploy@203.0.113.10:/srv/git/site.git $ git push -u production main To 203.0.113.10:/srv/git/site.git * [new branch] main -> main branch 'main' set up to track 'production/main'.Git leaves the user name out of the
Toline. Other machines get the code withgit clone deploy@203.0.113.10:/srv/git/site.git.
Why the server repository must be bare
Pushing to the checked-out branch of a normal repository is refused, because it would leave that repository’s files out of step with its history:
remote: error: refusing to update checked out branch: refs/heads/main
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
...
! [remote rejected] main -> main (branch is currently checked out)Setting receive.denyCurrentBranch to updateInstead in that repository lets the push update the working tree, as long as it has no uncommitted changes. For a deploy, a bare repository plus a hook is the cleaner split.
Deploy on push with a post-receive hook
#!/bin/sh
# Check out every push to main into the web root.
while read oldrev newrev ref; do
if [ "$ref" = "refs/heads/main" ]; then
git --work-tree=/var/www/site --git-dir=/srv/git/site.git checkout -f -q main
echo "Deployed $(git --git-dir=/srv/git/site.git rev-parse --short "$newrev") to /var/www/site"
fi
doneMake it executable with chmod +x, and make sure /var/www/site exists and belongs to the SSH user. Git runs the hook after every push and passes its output back, so the next git push production main printed:
remote: Deployed 6e31d01 to /var/www/site
To 203.0.113.10:/srv/git/site.git
14d32b5..6e31d01 main -> mainOn a server, keep one remote per destination (origin for the shared repository, production for the deploy target) and check with git remote -v before a push that matters. git push without a name goes to the remote of the current branch’s upstream, which may not be the one you expect.
Frequently asked
How do I see the remote URL of a Git repository?
Run git remote -v inside the repository: it lists every remote with its fetch and push URL. git remote get-url origin prints only the URL of origin, and git config --get remote.origin.url prints the value stored in .git/config. The first two show the URL after insteadOf rewrite rules, the last one the raw text.
Why does git branch -r not show a branch that exists on the server?
git branch -r lists your clone's remote-tracking branches, which only change when you fetch or pull. Run git fetch (or git fetch --prune to also drop branches deleted on the server) and list again. git ls-remote --heads origin asks the server directly and shows its branches without changing anything locally.
How do I change a Git remote from HTTPS to SSH?
Use git remote set-url origin git@HOST:OWNER/REPO.git, then check the result with git remote -v. Only the URL changes; branches, tracking and history stay the same. For SSH on a port other than 22, use the long form ssh://user@host:2222/path/repo.git or a host alias in ~/.ssh/config.
Can I push to my own server without a Git hosting service?
Yes. Create a bare repository on the server with git init --bare /srv/git/app.git as the SSH user, add it with git remote add production user@server:/srv/git/app.git and push with git push -u production main. A post-receive hook in that repository can check out each push into a web root.