Git remote

The git remote command is used to manage the set of repositories (“remotes”) whose branches you track. This is crucial for collaborating with others by connecting your local repository to remote repositories.



Tutorials dojo strip

Initial Example

To add a new remote repository, use:

git remote add <shortname> <url>




REMOTE Options

OptionDescription
-v, --verboseShow remote URLs after each remote name.
add <name> <url>Add a remote named <name> for the repository at <url>.
rename <old> <new>Rename the remote named <old> to <new>.
remove <name>Remove the remote named <name>.
set-head <name> [branch]Define the default branch for fetching. Use -d to delete, or specify a branch to set it.
set-branches <name> [branches]Change the list of branches tracked by <name>.
get-url <name>Retrieve the URLs for the remote named <name>.
set-url <name> <newurl> [oldurl]Change the URL for the remote named <name>. If <oldurl> is provided, it is replaced with <newurl>.
show <name>Show information about the remote named <name>.
prune <name>Delete stale tracking branches for <name>.
update [<name>...]Fetch updates from the specified remotes or all remotes if none are specified.




Examples

1. Adding a Remote Repository

To connect your local repository to a remote repository, use:

git remote add origin https://dev.azure.com/aCompiler/_git/DemoProject

This command adds a remote repository with the name origin and the specified URL.

2. Listing Remote Repositories

To see the list of all remote repositories associated with your local repository, use:

git remote -v

This will display the URLs for the remotes you have configured:

origin  https://dev.azure.com/aCompiler/_git/DemoProject (fetch)
origin  https://dev.azure.com/aCompiler/_git/DemoProject (push)

3. Removing a Remote Repository

If you need to remove a remote repository, use:

git remote remove <shortname>

For example, to remove the remote named origin, use:

git remote remove origin

4. Renaming a Remote Repository

To rename an existing remote repository, use:

git remote rename <oldname> <newname>

For instance, to rename origin to mainremote, use:

git remote rename origin mainremote
Scroll to Top