Git Workflow - First Exercise

1 min

Table of contents

  1. Initial Setup
  2. First Commit
  3. Modifications & Status
  4. Remote & Push
  5. Verification

1. Initial Setup

Mission: Create your first Git project from A to Z.

bash
# Create a folder and initialize Git
mkdir mon-premier-projet && cd mon-premier-projet
git init

# Check the status
git status    # Should show "On branch main, no commits yet"

Result: The .git/ folder is created = your project is now under Git!

Back to table of contents

2. First Commit

bash
# Create base files
echo "print('Hello World')" > app.py
echo "# Mon Premier Projet Git" > README.md

# See what Git sees
git status                    # "untracked" files

# Add to staging
git add .                     # All files
git status                    # Files "staged for commit"

# First commit
git commit -m "Initial commit: Hello World app"

# Check the history
git log --oneline

Result: Your first commit is in the history!

Back to table of contents

3. Modifications & Status

Mission: Learn the modify → add → commit cycle.

bash
# Modify app.py
echo "print('Hello Git!')" > app.py

git status                    # "modified: app.py"
git diff                      # See the changes

# Add the new modification
git add app.py
git status                    # "Changes to be committed"

# Commit
git commit -m "Update: Hello Git message"

# Add a new file
echo "def helper(): return True" > utils.py
git add utils.py && git commit -m "Add utils module"

# See the evolution
git log --oneline             # 3 commits now

Back to table of contents

4. Remote & Push

Mission: Connect your project to GitHub.

Step 1: Create a GitHub repo

  1. Go to github.com
  2. Create a new repository
  3. Copy the URL (e.g. https://github.com/ton-username/mon-projet.git)

Step 2: Connect local → GitHub

bash
# Add the remote (replace with your URL)
git remote add origin https://github.com/ton-username/mon-projet.git

# Check the connection
git remote -v                 # See the configured URL

# First push
git push -u origin main       # Push + setup tracking

# Later pushes are simpler
git push                      # That is enough now

Back to table of contents

5. Verification

Final checklist:

  • git status → "nothing to commit, working tree clean"
  • git log --oneline → at least 3 commits
  • Your code visible on GitHub
  • git remote -v → GitHub URL configured

Comprehension test:

  1. Make a modification:

    bash
    echo "print('Final version')" >> app.py
  2. Complete cycle:

    bash
    git status        # See the change
    git add app.py    # Stage
    git commit -m "Final update"    # Commit
    git push          # Share on GitHub
  3. Check on GitHub: Is your change visible?

If everything works → you master the basic Git workflow!

Next step: Learn branches to collaborate as a team.

Back to table of contents