Understand the difference between git push and pull with our step-by-step guide. Learn to set up repositories, commit changes, and resolve conflicts effortlessly.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Setting up Local and Remote Repositories
First, create a GitHub repository and clone it locally. You’ll use this setup to demonstrate both push and pull.
demo-push-pull.
# In your terminal, clone the empty repo
git clone https://github.com/your-username/demo-push-pull.git
cd demo-push-pull
Step 2: Understanding Local vs Remote
Git tracks two main locations for your code:
origin).Commands you run locally affect only your machine until you push to the remote. Commands that fetch or merge content from GitHub to your machine use pull.
Step 3: Making a Local Change and Committing
Create a file, add some content, and commit it. This prepares new work to send to GitHub.
# Create a README file
echo "# Demo Push Pull" > README.md
# Stage the change
git add README.md
# Commit locally
git commit -m "Add initial README"
Step 4: Pushing Local Commits to GitHub
git push sends your local commits up to the remote repository so others (and you on other machines) can access them.
origin refers to the default remote name.main is the default branch name (might be master in older repos).
# Push your 'main' branch to the remote named 'origin'
git push origin main
After running this, visit GitHub.com to confirm your README.md is visible online.
Step 5: Simulating a Remote-Only Change
To illustrate pull, create or edit a file directly on GitHub:
remote.txt and add any text.main.No changes have occurred on your local machine yet—you need git pull to fetch and integrate them.
Step 6: Pulling Remote Changes into Your Local Repo
git pull does two things: it fetches new commits from the remote, then merges them into your current branch.
# Fetch and merge remote changes
git pull origin main
remote.txt in your local folder.
Step 7: Handling Push/Pull Conflicts
Conflicts happen when both remote and local change the same lines. To simulate:
# Edit README.md locally
echo "Local edit" >> README.md
git add README.md
git commit -m "Local change to README"
# Meanwhile, edit README.md on GitHub UI and commit there
# Now try to push
git push origin main
git pull origin main, then resolve conflicts in your editor:
# After resolving conflict markers in README.md:
git add README.md
git commit -m "Resolve merge conflict in README"
git push origin main
Step 8: Key Takeaways on Push vs Pull
git fetch + git merge separately if you want more control.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.