Git Remote
Display Remote Repositories
Section titled “Display Remote Repositories”To list all configured remote repositories, use git remote.
It shows the short name (aliases) of each remote handle that you have configured.
$ git remotepremiumpremiumProoriginTo show more detailed information, the --verbose or -v flag can be used. The output will include the URL and the type of the remote (push or pull):
$ git remote -vpremiumPro https://github.com/user/CatClickerPro.git (fetch)premiumPro https://github.com/user/CatClickerPro.git (push)premium https://github.com/user/CatClicker.git (fetch)premium https://github.com/user/CatClicker.git (push)origin https://github.com/ud/starter.git (fetch)origin https://github.com/ud/starter.git (push)Change remote url of your Git repository
Section titled “Change remote url of your Git repository”You may want to do this if the remote repository is migrated. The command for changing the remote url is:
git remote set-urlIt takes 2 arguments: an existing remote name (origin, upstream) and the url.
Check your current remote url:
git remote -vorigin https://bitbucket.com/develop/myrepo.git (fetch)origin https://bitbucket.com/develop/myrepo.git (push)Change your remote url:
git remote set-url origin https://localserver/develop/myrepo.gitCheck again your remote url:
git remote -vorigin https://localserver/develop/myrepo.git (fetch)origin https://localserver/develop/myrepo.git (push)Remove a Remote Repository
Section titled “Remove a Remote Repository”Remove the remote named <name>. All remote-tracking branches and configuration settings for the remote are removed.
To remove a remote repository dev:
git remote rm devAdd a Remote Repository
Section titled “Add a Remote Repository”To add a remote, use git remote add in the root of your local repository.
For adding a remote Git repository
git remote add <name> <url>The command git fetch <name> can then be used to create and update remote-tracking branches <name>/<branch>.
Show more information about remote repository
Section titled “Show more information about remote repository”You can view more information about a remote repository by git remote show <remote repository alias>
git remote show originresult:
remote originFetch URL: https://localserver/develop/myrepo.gitPush URL: https://localserver/develop/myrepo.gitHEAD branch: masterRemote branches: master trackedLocal branches configured for 'git pull': master merges with remote masterLocal refs configured for 'git push': master pushes to master (up to date)Rename a Remote Repository
Section titled “Rename a Remote Repository”Rename the remote named <old> to <new>. All remote-tracking branches and configuration settings for the remote are updated.
To rename a remote branch name dev to dev1 :
git remote rename dev dev1Syntax
Section titled “Syntax”git remote [-v | --verbose]git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>]<name> <url>git remote rename <old> <new>git remote remove <name>git remote set-head <name> (-a | --auto | -d | --delete | <branch>)git remote set-branches [--add] <name> <branch>...git remote set-url [--push] <name> <newurl> [<oldurl>]git remote set-url --add [--push] <name> <newurl>git remote set-url --delete [--push] <name> <url>git remote [-v | --verbose] show [-n] <name>...git remote prune [-n | --dry-run] <name>...git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]git remote show <name>
Parameters
Section titled “Parameters”| Parameter | Details |
|---|---|
| -v, —verbose | Run verbosely. |
| -m | Sets head to remote’s |
| —mirror=fetch | Refs will not be stored in refs/remotes namespace, but instead will be mirrored in the local repo |
| —mirror=push | git push will behave as if —mirror was passed |
| —no-tags | git fetch <name> does not import tags from the remote repo |
| -t | Specifies the remote to track only |
| -f | git fetch <name> is run immediately after remote is set up |
| —tags | git fetch <name> imports every tag from the remote repo |
| -a, —auto | The symbolic-ref’s HEAD is set to the same branch as the remote’s HEAD |
| -d, —delete | All listed refs are deleted from the remote repository |
| —add | Adds |
| —add | Instead of changing some URL, new URL is added (set-url) |
| —all | Push all branches. |
| —delete | All urls matching |
| —push | Push URLS are manipulated instead of fetch URLS |
| -n | The remote heads are not queried first with git ls-remote <name>, cached information is used instead |
| —dry-run | report what branches will be pruned, but do not actually prune them |
| —prune | Remove remote branches that don’t have a local counterpart |