Remote Repositories, Fetch, Pull, and Push

A remote is a named repository connection. Once you know how to get and share commits through that connection, you can use GitHub to collaborate on the same project.

On this page

Clone an existing repository

Clone from the parent directory or another workspace if you want a new local copy. Git copies the repository history and usually names the remote origin. Replace OWNER with the account or organization name and use the actual repository URL.

git clone https://github.com/OWNER/project-notes.git
cd project-notes
git remote -v

Read remote changes before integrating them

In a repository that tracks origin/main, git fetch origin updates your local view of the remote branches without merging them into your current branch. Compare main with origin/main. On main with a clean working tree, git pull --ff-only fetches and advances main if it can do so without a merge commit. If the branches diverged, inspect the history before choosing how to integrate them.

git switch main
git fetch origin
git log --oneline main..origin/main
git pull --ff-only

Share commits on a feature branch

If you have write access, switch to or create a feature branch and push it to origin. The -u option records the upstream association so later pushes can use git push by itself. Continue with GitHub to learn how to open a pull request for the branch.

git switch -c update-notes
git push -u origin update-notes

Official references