Verify with Specific Remote
In the previous step, we used git ls-remote
with a full URL. You can also use git ls-remote
with the name of a remote that is already configured in your repository.
First, let's add a remote to our current repository. We'll add the same kernel.org Git repository as a remote named kernel_git
.
Run the following command:
git remote add kernel_git https://git.kernel.org/pub/scm/git/git.git
This command adds a remote named kernel_git
pointing to the specified URL. It won't produce any output if successful.
Now, let's use git ls-remote
with the remote name:
git ls-remote kernel_git
You should see the same output as when you used the full URL in the previous step.
<some_hash> refs/heads/master
<some_hash> refs/heads/next
<some_hash> refs/heads/pu
<some_hash> refs/heads/topic/add-options-to-git-config
...
Using git ls-remote
with a remote name is convenient when you have already added the remote to your configuration. It saves you from typing the full URL every time.
You can also specify what kind of references you want to see. For example, to only see branches, you can add refs/heads
:
git ls-remote kernel_git refs/heads
This will filter the output to show only the branches.
<some_hash> refs/heads/master
<some_hash> refs/heads/next
<some_hash> refs/heads/pu
<some_hash> refs/heads/topic/add-options-to-git-config
...
This demonstrates the flexibility of git ls-remote
for inspecting remote repositories.