~/hackweb.dev
Pushing and Pulling
Quiz
...

Pushing and Pulling

beginner · updated Tue Sep 08 2026Contribute

Sync your changes with a remote repository using push and pull.

Pushing and Pulling

Push sends your commits to a remote. Pull fetches and integrates changes from a remote.

Pushing Changes

git push origin main

Sends your local main commits to the origin remote.

Set Upstream

git push -u origin main

The -u flag sets origin main as the default upstream. After this, just run git push.

Pulling Changes

git pull origin main

Fetches and merges remote changes into your current branch.

Pull with Rebase

git pull --rebase origin main

Replays your local commits on top of the fetched changes instead of creating a merge commit.

What --set-upstream Does

git push --set-upstream origin feature

Links your local feature branch to the remote feature branch. After this, git push and git pull work without arguments.

Best Practices

  • Pull before pushing to avoid conflicts
  • Use --rebase for cleaner history
  • Set upstream once, then use shorthand commands
  • Push regularly to share progress with your team

Common Mistakes

  • Forgetting to pull before push
  • Pushing force to shared branches
  • Not setting upstream and getting errors
  • Pushing sensitive data accidentally