![]() |
VOOZH | about |
Git remote is a reference to a repository hosted externally on platforms like GitHub, GitLab, or your own server. It acts as a link between your local repository and a remote repository, allowing you to:
When you run git remote -v in your project, youβll often see a remote named origin. This is Gitβs default name for the remote repository URL you are connected to.
Think of it like a shortcut for the remote location where your code is stored (e.g., on GitHub or GitLab). It works like a key-value pair, where:
You will see origin used in many Git commands and messages, such as:
git push origin mainThis tells Git to push your local main branch to the remote repository named origin.
Git remote commands help you connect, manage, and interact with remote repositories like GitHub or GitLab. Here are the commonly used commands
To establish a connection between your local repository and a remote repository, use the following command:
git remote add origin <URL>To display a list of linked remote repositories along with their URLs for the local system user attempting to connect to a GitHub server.
git remote -vTo change the name of an existing remote that you are currently connected to on the server.
git remote rename <oldname> <newname>To unlink a remote repository from your local repo use the following command. If the repository name does not exist you can write origin instead of the repository name.
git remote remove <repositoryname>To display information about a specific remote, including branches and fetch/push URLs use the following command.
git remote show <name> To create a local copy of a remote repository, use:
git clone <remote-repository-URL>This downloads the entire repository along with its history.
To retrieve updates from a remote repository without merging them:
git fetch <remote-name>To fetch and merge the latest changes from a remote repository into your local branch:
git pull <remote-name> <branch-name>After making changes locally, push them to the remote repository:
git push <remote-name> <branch-name>If pushing for the first time, use
git push --set-upstream origin mainTo see all branches available on the remote repository:
git branch -rTo create a local branch that tracks a remote branch:
git checkout --track origin/<branch-name>To remove a branch from the remote repository:
git push origin --delete <branch-name>If Git keeps asking for a username and password multiple times, consider setting up SSH authentication:
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"Add the public key to your GitHub/GitLab account.
If conflicts arise while pulling changes, manually resolve them and commit:
git add .
git commit -m "Resolved merge conflicts"
git push origin main
If Git shows "repository not found", update the remote URL:
git remote set-url origin <correct-URL>If access is denied:
Below are some of the most useful Git remote commands that developers commonly use in real projects:
| Command | Description |
|---|---|
| git remote add <name> <url> | Adds a new remote repository (e.g., origin) |
| git remote -v | Shows all remotes and their fetch/push URLs |
| git remote rename <old> <new> | Renames an existing remote |
| git remote remove <name> | Removes a remote from the local repository |
| git remote show <name> | Shows detailed info about a remote (branches, URLs, etc.) |
| git remote set-url <name> <new-url> | Updates the URL of an existing remote |
| Command | Description |
|---|---|
| git clone <url> | Clones a remote repository to your local machine |
| git fetch <remote> | Fetches changes from the remote without merging |
| git pull <remote> <branch> | Fetches and merges changes from a remote branch |
| git push <remote> <branch> | Pushes your local branch to a remote branch |
| git push --set-upstream origin <branch> | Sets upstream for tracking and pushes branch to remote |
| Command | Description |
|---|---|
| git branch -r | Lists all remote-tracking branches |
| git checkout --track origin/<branch> | Creates a local branch tracking a remote branch |
| git push origin --delete <branch> | Deletes a branch from the remote repository |
| git remote prune origin | Removes references to deleted branches from the remote |