In the previous post, I introduced you to the concept of Git remotes. I showed you that a Git repository can have more than one remote and how you can fetch data from a particular remote.
In this post, I am about to answer the following questions:
- How do you view more details about a particular remote? The branches present in the remote, and how those branches map to your local branches.
- How do you rename a remote?
- How do you stop tracking (remove) a remote from your Git repository?
View (Inspect) a Git remote
The command to achieve this is: git remote show <shortname>
. For example, the sample output of running git remote show origin
is shown below.
* remote origin
Fetch URL: [email protected]:ayushpoddar/colorls.git
Push URL: [email protected]:ayushpoddar/colorls.git
HEAD branch: main
Remote branches:
color-hidden-files tracked
main tracked
show-abs-path-xargs tracked
size-in-bytes tracked
Local branches configured for 'git pull':
color-hidden-files merges with remote color-hidden-files
main merges with remote main
show-abs-path-xargs merges with remote show-abs-path-xargs
size-in-bytes merges with remote size-in-bytes
Local refs configured for 'git push':
color-hidden-files pushes to color-hidden-files (up to date)
main pushes to main (up to date)
show-abs-path-xargs pushes to show-abs-path-xargs (up to date)
size-in-bytes pushes to size-in-bytes (up to date)
I want you make the following observations:
- This command outputs the full URL of the remote that the shortname is mapped to.
- The list of branches in remote have been “fetched” to your local repository.
- It lists the mapping between your local branches and remote branches. This helps you with knowing
the remote branch that will be used when running
git pull
orgit push
on a local branch.
How to rename a remote shortname?
Simple command.
git remote rename <old-shortname> <new-shortname>
How to remove a remote?
If you want to stop tracking a remote, you need to remove all references to the remote from your local repository. The command to do so is:
git remote remove <shortname>
# rm is an alias for remove
git remote rm <shortname>
Final words
After reading the first post and this post, you are
equipped enough to understand any advanced ideas or commands that you may encounter. You can explore
more on your own using man git-remote
or git help remote
.