GH-900 ยท Version control and Git
Remotes and syncing
Local versus remote repositories, origin, and the difference between git fetch, pull and push.
Key points
- Your local repository is the copy on your machine; a remote is a copy hosted elsewhere, such as on GitHub.
- When you clone, the remote is named origin by default. git fetch downloads new commits and updates remote-tracking branches like origin/main without changing your working files. git pull is a fetch followed by integrating the changes into your current branch. git push uploads your local commits to the remote.
Source: https://git-scm.com/docs/git-pull
Practice questions
What is the default name Git gives the remote you cloned from?
- origin
- main
- upstream
- remote
Show answer
Answer: A. origin
git clone names the source remote origin unless you override it. main is a branch name, upstream is a convention for a forked source, and remote is not a default name.
Which statements about fetch, pull and push are correct?
- git fetch downloads new commits without merging them into your branch
- git pull fetches and then integrates changes into the current branch
- git push uploads local commits to a remote
- git push downloads teammates' commits
- git fetch deletes your local commits
Show answer
Answer: A. git fetch downloads new commits without merging them into your branch, B. git pull fetches and then integrates changes into the current branch, C. git push uploads local commits to a remote
fetch downloads without integrating, pull fetches and then integrates, and push uploads local commits. push does not download changes.
True or false: making a commit on your computer automatically uploads it to the remote repository.
Show answer
Answer: False
False. A commit is local until you run git push.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
