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
--rebasefor 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