Push and pull: sharing your work
Push sends your commits up to the shared server. Pull brings your teammates' commits down to your laptop. Together they keep everyone's copy in sync.
Commits you make on your laptop are private until you push them. Nobody on your team can see them. Likewise, work your teammates push stays invisible to you until you pull it. Push and pull are how the copies talk to each other.
Push: send your work up
You've made a few commits on your branch. To share them:
git push
That's usually all. Git sends your new commits to origin (the shared copy on Sangam-Git). Now teammates can see them, and they appear on the website.
The first time you push a brand-new branch, tell Git where it should live on the server:
git push -u origin feat/upi-payments
After that first push, plain git push remembers the rest.
Pull: bring others' work down
Your teammate Arjun pushed a fix an hour ago. To get it onto your laptop:
git pull
Git downloads his new commits from origin and updates your files. Now you're up to date.
The daily rhythm
On a real team, this becomes a habit:
- Pull first thing in the morning, so you start from the latest.
- Do your work; commit in small pieces.
- Push when you've finished something and want to share it.
- Pull again before you push, in case teammates pushed while you worked.
git pull # start fresh
# ...write code, then...
git add .
git commit -m "Add Hindi labels to the payment screen"
git pull # grab anything new before sending
git push # share your work
Fetch: look before you leap
git pull actually does two things: it fetches (downloads new commits) and then merges them into your work. If you want to download and look before merging, use fetch on its own:
git fetch
git log origin/main --oneline # see what's new on the server
Most days you'll just use pull. fetch is there for when you want a peek first.
"Your branch is behind" and other messages
Sometimes a push is rejected with "updates were rejected because the remote contains work that you do not have locally." This simply means a teammate pushed something you haven't pulled yet. The fix is friendly:
git pull # bring their work in (may create a merge, see the merge page)
git push # now your push is accepted
Git is protecting you from accidentally overwriting someone else's work.
Remember: commit saves locally; push shares it. Nothing you commit affects the team until you push, and you won't see their latest until you pull.