CLI GUIDE

What is Git?

Git is a version control system that lets you track changes in your code over time. It's like "Ctrl+Z" on steroids - you can always go back to previous versions. GitHub, GitLab, and Bitbucket use Git to store and share code.

git init

Initialize Repository

What does it do?

Starts a new Git repository in the current folder. This is the first thing you do when you want to start using Git in a project.

Example:

$ cd my-project $ git init Initialized empty Git repository in /Users/name/my-project/.git/

When to use it:

  • First time setting up Git in a new project
  • When you want to start tracking changes
  • Before you can use other Git commands

git status

Check Repository Status

What does it do?

Shows you the status of your repository - which files have been modified, which are staged, and which branch you're on.

Example:

$ git status On branch main Changes not staged for commit: modified: index.html modified: style.css Untracked files: script.js

When to use it:

  • Before committing to see what has changed
  • Check if there's anything to push to GitHub
  • See which branch you're working on
💡 Pro-tip: Use git status often! It's the command you'll use the most.

git add

Stage Changes

What does it do?

Adds files to the "staging area" - making them ready to be committed. You must always "add" before you "commit".

Example:

$ git add index.html # Adds one specific file
$ git add . # Adds ALL changed files (most commonly used)
$ git add *.css # Adds all CSS files

When to use it:

  • After you've changed files and want to save the changes
  • Before each commit
  • When you want to choose specific files to commit

Common options:

  • git add . - Add all files in current directory
  • git add -A - Add all files in entire project
  • git add -p - Interactive mode (choose what to add)

git commit

Save Changes

What does it do?

Saves your staged changes with a descriptive message. This is a "checkpoint" in your project's history.

Example:

$ git commit -m "Add contact form" # -m lets you write the message directly
$ git commit -m "Fix: Correct navigation bug" # Good practice: start with what type of change it is
$ git commit -am "Update README" # -a adds and commits in one operation

When to use it:

  • After completing a feature or fixing a bug
  • When you have a logical "package" of changes
  • Before switching to another branch

Tips for good commit messages:

  • Use present tense: "Add" not "Added"
  • Be descriptive: "Fix: Correct validation" not "fixed something"
  • Keep them short but informative (under 50 characters)

git push

Upload to Remote

What does it do?

Uploads your local commits to a remote repository (like GitHub). This shares your code with others.

Example:

$ git push origin main # Pushes main branch to GitHub
$ git push -u origin new-feature # Pushes and sets up tracking for a new branch
$ git push # If tracking is already set up

When to use it:

  • When you want to share your code with others
  • To backup your work to GitHub
  • Before asking someone for code review

git pull

Download from Remote

What does it do?

Fetches and merges changes from the remote repository to your local copy. Important when working in teams.

Example:

$ git pull origin main # Fetches latest changes from GitHub
$ git pull # If tracking is set up

When to use it:

  • Before you start working (to get the latest version)
  • When others have pushed changes
  • To sync local copy with GitHub
💡 Pro-tip: Always run git pull before you start working, especially in team projects!

git clone

Copy Repository

What does it do?

Downloads a complete copy of a repository from GitHub to your machine.

Example:

$ git clone https://github.com/user/repo.git # Downloads repository from GitHub
$ git clone https://github.com/user/repo.git my-project # Downloads to a specific folder

When to use it:

  • First time working with an existing project
  • When contributing to open source
  • To get a local copy of a GitHub repo

🎯 Typical Git Workflow

$ git status # 1. See what has changed $ git add . # 2. Add all changes $ git commit -m "Description" # 3. Commit with message $ git push origin main # 4. Push to GitHub

🔧 Useful Git Commands

  • git diff - See what has changed since last commit
  • git log --oneline - View commit history
  • git branch - List all branches
  • git checkout -b new-branch - Create and switch to new branch
  • git stash - Temporarily store changes
  • git remote -v - See which GitHub repo you're connected to

Become a Git Master

Check out tips and tricks to become even more efficient

See Tips & Tricks →