Tutorial 7 · beginner · 12 min

Remotes and pull requests

Clone, fetch, pull and push, then open a pull request. How Git workflows play out on GitHub and GitLab.

Updated

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

Clone

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

Fetch, pull, push

git fetch            # download new commits; doesn't touch your files
git pull             # fetch + integrate into your current branch
git push             # upload your commits

The first time you push a new branch, set its upstream:

git push -u origin feature/search

After that, plain git push and git pull know where to go.

Remote-tracking branches

After a fetch, origin/main shows where main is on the remote. Compare before you pull:

git fetch
git log --oneline main..origin/main    # commits you don't have yet

The pull request loop

Whatever your workflow (Gitflow, GitHub Flow or trunk-based), the daily rhythm on a hosted repo looks like this:

  1. git switch -c feature/search main (or develop in Gitflow)
  2. Commit in small steps.
  3. git push -u origin feature/search
  4. Open a pull request (GitLab calls it a merge request) against the right target branch.
  5. CI runs, teammates review, you push fixes to the same branch.
  6. Merge, then delete the branch.

Merge buttons explained

Option Result
Create a merge commit Keeps every commit plus a merge commit (like --no-ff)
Squash and merge All PR commits become one commit on the target
Rebase and merge Commits replayed on top, no merge commit

Gitflow teams usually choose merge commit for release and hotfix PRs, so both main and develop keep the same history.

Stay in sync

git switch main && git pull
git switch feature/search && git rebase main   # or: git merge main

Delete local branches whose remote branch is gone:

git fetch --prune

One Git tip a week

Short, practical, no spam. Get the free printable Gitflow cheat sheet when you join.

Newsletter launching soon.