Git Sync with GitHub

1 min

Table of contents

  1. Local ↔ GitHub Sync
  2. Quick Setup
  3. Push/Pull Workflow
  4. Conflict Management
  5. Essential Commands

1. Local ↔ GitHub Sync

Goal: Keep your local code synchronized with GitHub.

The problem:

  • You code locally
  • The team modifies on GitHub
  • How do you stay up to date?

The solution: Push (you → GitHub) and Pull (GitHub → you)

Back to table of contents

2. Quick Setup

bash
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 main

That's all! Your code is on GitHub.

Back to table of contents

3. Push/Pull Workflow

Typical scenario:

Push: You → GitHub

bash
# You modify locally
echo "print('v2 updated')" > app.py
git add . && git commit -m "Update to v2"

# Send to GitHub
git push origin main

Pull: GitHub → You

bash
# 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

Daily Workflow

bash
# 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 push

Back to table of contents

4. Conflict Management

Conflict = You and a colleague modify the same line.

Conflict simulation:

bash
# 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!

Resolution:

bash
# 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 push

Conflict resolved! The team retrieves your merged version.

Back to table of contents

5. Essential Commands

CommandAction
git clone <url>Copy a GitHub repo
git remote add origin <url>Connect to GitHub
git push -u origin mainFirst push (with tracking)
git pushSend your commits
git pullRetrieve + merge
git fetchRetrieve without merging
git statusSee the sync state

Basic workflow:

  1. git pull (retrieve)
  2. Develop + git add + git commit
  3. git push (share)
  4. Repeat!

GitHub sync = A developer's breathing: pull → code → push!

Back to table of contents