Git Workflow & Commands

1 min

Table of contents

  1. Local vs Remote
  2. Basic Workflow
  3. Essential Commands
  4. Daily Cycle

1. Local vs Remote

Local = On your PC

  • You code, modify, commit
  • Private, nobody else sees it
  • Works offline

Remote = On a server (GitHub)

  • Code shared with the team
  • Online backup
  • Requires Internet

Simple analogy: Local = draft, Remote = shared final version.

Back to table of contents

2. Basic Workflow

1. MODIFY your files
     ↓
2. git ADD (stage)
     ↓
3. git COMMIT (save locally)
     ↓
4. git PUSH (send to remote)

Visual:

Working Directory → Staging Area → Local Repo → Remote Repo
     edit             add           commit        push

Back to table of contents

3. Essential Commands

Daily:

CommandAction
git statusSee the state of the files
git add .Stage all changes
git commit -m "message"Commit with a message
git pushSend to remote
git pullRetrieve from remote

Initial setup:

CommandAction
git initInitialize a local repo
git clone <url>Copy a remote repo
git remote add origin <url>Connect to the remote

Information:

CommandAction
git log --onelineConcise history
git diffSee the changes
git branchList the branches

Back to table of contents

4. Daily Cycle

Morning: Retrieve the team's work

bash
git pull origin main    # Synchronize with the team

Daytime: Develop

bash
# Modify your files...
git status              # See what changed
git add .               # Stage all changes
git commit -m "Add new feature"    # Commit

Evening: Share your work

bash
git push origin main    # Send your commits

Ultra-fast workflow:

bash
git add . && git commit -m "Quick update" && git push

In case of emergency:

bash
git stash              # Save work in progress
# Urgent fix...
git stash pop          # Recover your work

Golden rules:

  1. Always pull before pushing
  2. Commit often, push daily
  3. Descriptive commit messages
  4. Never push broken code

That's all! Master these commands = 90% of your daily Git usage.

Back to table of contents