The Essential Git Command List
When you're just getting started with Version Control, jumping into Git can feel like learning a new language. There are so many powerful commands to master!
But fear not; on this page, we will keep it simple and focus on the most fundamental Git commands — the ones you will actually use every day. Think of it as your trusty pocket guide to help your version control process flow smoothly.
Let's dive in and get you Git-ing like a pro! đź’Ş
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
The 9 Core Commands You Need to Know
Here are the absolute essentials to get you started and keep your project history in check.
1. Cloning a Repository: git clone
What it does: Downloads an existing Git repository from a remote URL to your local machine. This is how you get a copy of a project to start working on.
Example:
git clone https://github.com/user/repository.git
The git clone command will create a directory named "repository" in your current location, containing all the files and the complete history of the remote repository.
2. Checking the Status: git status
What it does: Shows you the current state of your working directory and the staging area. It helps you see which files have been modified, which are staged for commit, and which are being tracked by Git.
Example:
git status
The git status command will output information about any changes you've made, whether they are staged, unstaged, or untracked.
3. Adding Changes to the Staging Area: git add
What it does: Stages changes in your working directory for the next commit. With the git add command, you specify exactly which changes you want to include in your snapshot.
Examples:
- Stage a specific file:
git add filename.txt
- Stage all changes in the current directory and its subdirectories:
git add .
4. Committing Changes: git commit
What it does: Saves the staged changes along with a descriptive message to your local repository's history. The git commit command creates a snapshot of your project at a specific point in time.
Example:
git commit -m "Add new feature and fix minor bugs"
The -m
flag allows you to write your commit message directly in the command line. Always aim for clear and concise commit messages!
5. Pushing Changes to a Remote Repository: git push
What it does: Uploads your local commits to a remote repository (like GitHub, GitLab, or Bitbucket), allowing others to see your changes and collaborate.
Example:
git push origin main
With the git push command, you always need to specify which remote branch you want to push to. Here, origin
is the common name for your main remote repository, and main
is the branch you're pushing to.
6. Pulling Changes from a Remote Repository: git pull
What it does: Downloads changes from a remote repository and integrates them into your current local branch. This is how you stay up-to-date with the work of others.
Example:
git pull origin main
The git pull command fetches changes from the main
branch of the origin
remote and merges them into your currently active main
branch.
7. Creating a New Branch: git branch
What it does: Creates a new, independent line of development in your local repository. Branching allows you to work on new features or fixes without affecting the main codebase. This is good practice, so you will use the git branch command often!
Examples:
- Create a new branch:
git branch feature-x
- Delete a branch:
git branch -d feature-x
8. Switching Between Branches: git checkout
What it does: Allows you to navigate between the branches you've created or that exist in the repository. The git checkout command updates your working directory to reflect the state of the chosen branch.
Examples:
- Switch to an existing branch:
git checkout feature-x
- Create and switch to a new branch in one command:
git checkout -b new-feature
9. Merging Branches: git merge
What it does: Integrates the changes from one branch into your currently active branch. This is how you combine the work done on different branches.
Example:
To merge the "feature-x" branch into your current branch (e.g., main
), you would first switch to main
:
git checkout main
git merge feature-x
Git will then attempt to automatically integrate the changes from "feature-x" into "main". When running the git merge command, please keep in mind that you might encounter merge conflicts that need manual resolution.
Keep Leveling Up!
These commands are your bread and butter for most Git workflows. Mastering them will give you a solid foundation for collaborating on projects and managing your codebase effectively.
Keep practicing, and be sure to explore our Learn Git section to discover everything you can achieve with Git.
Get our popular Git Cheat Sheet for free!
You'll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.
About Us
As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.
Just like with Tower, our mission with this platform is to help people become better professionals.
That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.