appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Remotes, fetch, pull and push

Lesson 1 of 411 minIntermediate

Share work through a remote repository and understand what each command moves.

A remote is another copy of the repository, usually on GitHub, GitLab or a server. By convention the main one is called origin.

git remote -v                       # list remotes
git clone https://example.com/team/app.git
git fetch origin                    # download new commits, change nothing locally
git pull                            # fetch + merge into the current branch
git push -u origin my-branch        # upload and remember the upstream

Fetch vs pull

git fetch only updates your view of the remote (origin/main). git pull fetches and then integrates the changes into your branch. When you want to look before you merge, fetch first.

A pull request workflow

  1. Update main: git switch main && git pull.
  2. Create a branch: git switch -c fix-login-bug.
  3. Commit small, focused changes.
  4. Push the branch and open a pull request (PR) so others can review it.
  5. Fix review comments with new commits, then merge when approved.

CarefulPush is rejected when the remote has commits you do not have. Pull (or rebase) first. Never solve it with git push --force on a shared branch: it erases other people's work.

Notegit push --force-with-lease is the safer force: it refuses if someone else pushed since your last fetch. Use it only on branches that are yours.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. What does git fetch do?
2. Your push is rejected because the remote has new commits. What should you do?
Hintgit remote with the verbose flag.

Key terms