Sub topic 7
Verifying your clone
This chapter assumes you have Git installed, a GitHub account, and a working git clone from the previous chapters. You should also know what a commit and a branch are. Here you will check that a fresh clone is complete and correctly wired to GitHub.
Why verify
A clone can finish without errors and still not be what you wanted. You might have cloned into the wrong directory, landed on an unexpected branch, or received a shallow history. Four quick commands answer these questions before you start work.
The four checks
Run these inside the new directory:
cd Hello-World
git status
git remote -v
git branch -a
git log --oneline -n 5Each command checks one part of the result of a clone.
| Command | What it confirms |
|---|---|
| `git status` | The current branch and whether the working tree is clean |
| `git remote -v` | The URL that `origin` points to, for fetch and push |
| `git branch -a` | Local branches and remote-tracking branches |
| `git log --oneline -n 5` | That commit history was downloaded |
Reading git status
On a fresh clone, the output looks like this:
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree cleanThe first line names the checked-out branch. It is the repository's default branch on GitHub, which is master for Hello-World and main for most newer repositories. The second line shows that the local branch tracks a remote-tracking branch. "Working tree clean" means no files have been edited.
Reading git remote -v
origin https://github.com/octocat/Hello-World.git (fetch)
origin https://github.com/octocat/Hello-World.git (push)Git named the source remote origin. Check that the URL uses the protocol you intended. If you wanted SSH but see https://, you cloned over HTTPS, and pushes will ask for HTTPS credentials.
Reading git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/testOnly one local branch exists, the one that was checked out. The remotes/origin/... entries are remote-tracking branches. They are your local record of where each branch on GitHub was at the time of the clone. The HEAD -> line shows which branch is the remote's default.
Reading git log
git log --oneline -n 5 prints the five newest commits, one per line, each with a short hash and message. If the log is short or ends abruptly, the clone may be shallow. You can confirm that with:
git rev-parse --is-shallow-repositoryThis prints true for a clone made with --depth and false for a full clone.
Common findings
- Wrong branch:
git statusshows a branch you did not expect. Check the default branch on GitHub, or re-clone with--branch. - Wrong protocol:
git remote -vshows HTTPS when you wanted SSH. Fix it withgit remote set-url origin [email protected]:octocat/Hello-World.git. - Missing history: the log is shorter than the repository's history on GitHub. The clone is shallow, and
git fetch --unshallowdownloads the rest. - Empty directory or no
.git: the clone failed partway. Delete the directory and run it again.
Checking the .git directory
All repository data lives in the hidden .git directory. A quick sanity check is:
ls -a
git rev-parse --git-dirThe first command lists hidden files, so you should see .git. The second prints .git, which confirms that Git recognizes the directory as a repository.
Exercise
You cloned a repository and git status says "Your branch is up to date with 'origin/main'". A teammate just pushed a commit to GitHub. Why does Git still say you are up to date, and which command shows the difference?
Show answer
git status compares your branch with the remote-tracking branch origin/main, which is only updated when you contact GitHub. Run git fetch origin to update it. After that, git status reports that your branch is behind.
Exercise
After cloning with --depth 1, which command tells you whether the repository is shallow, and what does it print?
Show answer
git rev-parse --is-shallow-repository prints true for a shallow clone.