Remotes, GitHub and collaboration
Clone, push and pull, and the pull request workflow.
A remote is a copy of the repository hosted elsewhere, such as GitHub or GitLab. By convention the main one is called origin.
git clone https://github.com/user/project.git # copy a remote repo locally
git remote -v # show remotes
git push origin main # upload your commits
git pull # download and merge new commits
git fetch # download without mergingAuthentication
Use an SSH key or a token instead of your password. Add your public key to your GitHub account and clone with the git@github.com:user/project.git form.
The pull request workflow
- Create a branch for your change.
- Commit and
git push -u origin your-branch. - Open a pull request on the hosting site so others can review it.
- Address comments, then merge.
- Delete the branch and
git pullon main.
Notegit pull is git fetch plus a merge. If you want to inspect changes first, run git fetch and then git log origin/main.
CarefulAvoid git push --force on shared branches: it rewrites history others already have.
Try it
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.