Goal: Keep your local code synchronized with GitHub.
The problem:
The solution: Push (you → GitHub) and Pull (GitHub → you)
mkdir demo-github-sync && cd demo-github-sync
git init
echo "print('v1')" > app.py
echo "# Demo GitHub Sync" > README.md
git add . && git commit -m "Initial commit"
# Connect to GitHub (replace with your repo)
git remote add origin https://github.com/ton-username/demo-repo.git
# First push
git push -u origin mainThat's all! Your code is on GitHub.
Typical scenario:
# You modify locally
echo "print('v2 updated')" > app.py
git add . && git commit -m "Update to v2"
# Send to GitHub
git push origin main# Retrieve the team's changes
git pull origin main
# Or in 2 steps:
git fetch origin # Download without merging
git merge origin/main # Merge afterwards# Morning: retrieve the team's work
git pull
# Daytime: you develop
echo "print('new feature')" >> app.py
git add . && git commit -m "Add feature"
# Evening: push your work
git pushConflict = You and a colleague modify the same line.
# Your colleague modified app.py on GitHub
# You did too locally
echo "print('my version')" > app.py
git add . && git commit -m "My changes"
git pull # CONFLICT!# Git shows you the conflict in app.py:
# <<<<<<< HEAD
# print('my version')
# =======
# print('colleague version')
# >>>>>>> abc123
# Edit the file to keep what you want:
echo "print('merged version')" > app.py
# Finalize the resolution:
git add app.py
git commit -m "Resolve conflict"
git pushConflict resolved! The team retrieves your merged version.
| Command | Action |
|---|---|
git clone <url> | Copy a GitHub repo |
git remote add origin <url> | Connect to GitHub |
git push -u origin main | First push (with tracking) |
git push | Send your commits |
git pull | Retrieve + merge |
git fetch | Retrieve without merging |
git status | See the sync state |
git pull (retrieve)git add + git commitgit push (share)GitHub sync = A developer's breathing: pull → code → push!