T

TechIdea

Ecosystem

Back to Commands
git COMMANDS

Git Commands Cheat Sheet

Essential Git commands for modern version control. Includes examples, syntax, and tips for committing, branching, and merging.

git clone

Downloads a copy of an existing remote repository to your local machine.

Syntax

bash
git clone <url>

Example

bash
git clone https://github.com/user/project.git

Pro Tip

You can append a folder name to clone it directly into a specific folder: `git clone <url> new-folder`

Common Mistake

Running this command inside an existing git repository folder. Always clone into an empty directory.

git status

Shows the state of your working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git.

Syntax

bash
git status

Example

bash
git status

Pro Tip

Run this command constantly! It is the best way to avoid accidentally committing the wrong files.

Common Mistake

Ignoring untracked files in the output.

git add

Adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.

Syntax

bash
git add <file-name>
git add .

Example

bash
git add index.html
git add .

Pro Tip

Use `git add -p` to stage changes in chunks (hunks) interactively.

Common Mistake

Using `git add .` without running `git status` first, accidentally committing secret `.env` files.

git commit

Captures a snapshot of the project's currently staged changes.

Syntax

bash
git commit -m "message"

Example

bash
git commit -m "Fix navigation bar bug on mobile"

Pro Tip

Use `git commit -am "message"` to skip the `git add` step for files that are already being tracked.

Common Mistake

Writing bad commit messages like 'fixed bug' or 'update'.

git push

Uploads local repository content to a remote repository.

Syntax

bash
git push <remote> <branch>

Example

bash
git push origin main

Pro Tip

Use `git push -u origin feature-branch` the very first time you push a new branch to set the upstream link.

Common Mistake

Pushing directly to the `main` branch instead of creating a Pull Request on a feature branch.

git pull

Fetches and downloads content from a remote repository and immediately updates the local repository to match.

Syntax

bash
git pull <remote> <branch>

Example

bash
git pull origin main

Pro Tip

`git pull` is actually a combination of two commands: `git fetch` followed by `git merge`.

Common Mistake

Running `git pull` when you have uncommitted changes. Git might abort the pull or create messy merge conflicts.

git branch

Lists, creates, or deletes branches.

Syntax

bash
git branch
git branch <branch-name>

Example

bash
git branch feature-login
git branch -d feature-login

Pro Tip

Run `git branch -a` to see both local and remote branches.

Common Mistake

Creating a branch and thinking you are instantly switched to it. (You must use `checkout`).

git checkout

Switches branches or restores working tree files.

Syntax

bash
git checkout <branch-name>
git checkout -b <new-branch-name>

Example

bash
git checkout main
git checkout -b feature-login

Pro Tip

In newer versions of Git, you can use `git switch` instead of `checkout` to change branches.

Common Mistake

Forgetting the `-b` flag when trying to create a *new* branch, resulting in a 'pathspec did not match any file' error.

Growth Newsletter

Get practical AI tools, SEO tips, and growth guides weekly.

Join creators, students, and businesses scaling with TechIdea.