git remote: connect a repository to another one
A remote is a name for a URL, which may be a path on the same machine or a remote address; fetch and push URLs can differ.
Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.
TE-16-A: a remote can be a path on the same machine, not only a server
Setup for this run, inside a throwaway directory (mktemp -d):
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
git init -q --bare ../bare.gitPaths written as ../name sit one level above the repository folder, inside the same throwaway tree, so they do not appear in git status.
Command:
git remote add origin ../bare.git; git push -q origin HEAD:main; echo push=$?Recorded output:
push=0Check command and its recorded output:
git remote -v | head -1; git ls-remote --heads origin | wc -lorigin ../bare.git (fetch)
1TE-16-B: git remote -v lists the fetch and push address of a remote added with a relative path
Setup for this run, inside a throwaway directory (mktemp -d):
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
git init -q --bare ../bare.git
git remote add origin ../bare.gitCommand:
git remote -vRecorded output:
origin ../bare.git (fetch)
origin ../bare.git (push)Exit status: 0. This status and the output match what was written before the run.
TE-16-C: expected non-zero exit: pushing to a remote name that has not been added stops with a fatal error
Setup for this run, inside a throwaway directory (mktemp -d):
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm oneCommand:
git push -q nosuch HEAD:mainRecorded output: none, standard output was empty.
Standard error from the same run:
fatal: 'nosuch' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.Exit status: 128. This status and the output match what was written before the run.
Reading the recorded output
The line push=0 is the exit status of git push to ../bare.git, a bare repository in a folder on the same machine. git remote -v printed origin with the path ../bare.git and the word fetch in parentheses as its first line, and the run keeps only that first line. For git ls-remote --heads origin the run printed the count of branch lines, which is 1, so the bare repository has one branch after the push.
TE-16-B: git remote -v printed origin ../bare.git (fetch) and origin ../bare.git (push), the path given to git remote add. TE-16-C: git push to the name nosuch exited with status 128. The first line of standard error is fatal: 'nosuch' does not appear to be a git repository.
Limits
A remote may be a path on the same machine or a URL; it is not necessarily a server on the internet.
Source
Evidence
TE-16-A: a remote can be a path on the same machine, not only a server
- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.
Evidence table
| Test | What it checks | Exit | Verdict | Log sha256 (first 12) | |---|---|---|---|---| | TE-16-A | a remote can be a path on the same machine, not only a server | 0 | PASS | 4512703726ee | | TE-16-B | git remote -v lists the fetch and push address of a remote added with a relative path | 0 | PASS | edf08938ac8f | | TE-16-C | expected non-zero exit: pushing to a remote name that has not been added stops with a fatal error | 128 | PASS | b9b09d92a2ae |
Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.
All full guides: All guides