Git Cheat Sheet

Git Cheat Sheet

Seamless UI Component Library for Tailwind CSS

FlyonUI is a Tailwind CSS UI components library
with semantic classes and powerful JS plugins. Includes blocks,
templates, a Figma design system, and more…

Get Started

Build. Commit. Translate.

Lingo.dev offers AI localization for teams who ship fast. Translate apps, websites, and entire databases using the best LLM models.

Don’t forget to star the repo

Navigate essential Git commands with this comprehensive cheat sheet, designed to help you handle version control efficiently and confidently.

Let’s get started!

1. Initialize a new Git repository.

The git init command initializes a new, empty Git repository in the current directory, creating a .git folder that tracks changes to files within the repository:

bash
git init

2. Set configuration values for your username and email.

Use git config to set your name and email so your commits are properly attributed:

bash
git config --global user.name <your-name>
git config --global user.email <your-email>

3. Clone a repository.

Copy a remote repository to your local machine with git clone  to start working on it:

bash
git clone <repository-url>

4. Add a file to the staging area.

Move changes into the staging area with git add so they’re ready to be committed:

bash
git add <file>

5. Check the unstaged changes.

View the changes in your working directory that haven’t been staged yet using git diff:

bash
git diff

6. Commit the staged changes.

Record the staged changes in the repository’s history with git commit and a descriptive message.

bash
git commit -m "Add new amazing feature"

7. Reset staging area to the last commit.

Unstage changes and revert the staging area to match the last commit using git reset.

bash
git reset

8. Check the state of the working directory and the staging area.

See the current status of tracked, untracked, and staged changes in your repository with git status.

bash
git status

9. Remove a file from the index and working directory.

Delete a file from both the staging area and your working directory using git rm:

bash
git rm <file>

10. List the commit history.

Display the project’s commit history with git log to see past changes and their details:

bash
git log

11. Check the metadata and content changes of the commit.

Inspect a commit’s details, including its metadata and file changes, using git show:

bash
git show <commit-hash>

12. List all local branches.

Display all branches in your local repository with git branch:

bash
git branch

13. Create a new branch.

Create a new branch to work on a separate line of development using git branch <branch-name>

bash
git branch <branch-name>

14. Rename the current branch.

Change the name of the current branch using git branch -m <new-branch-name>:

bash
git branch -m <new-branch-name>

15. Delete a branch.

Remove a local branch that is no longer needed with git branch -d <branch-name>.

bash
git branch -d <branch-name>

16. Switch to another branch.

Move to a different branch in your repository using git switch <branch-name> or git checkout <branch-name>.

bash
git checkout <branch-name>

17. Merge specified branch into the current branch.

Combine changes from another branch into your current branch using git merge <branch-name>.

bash
git merge <branch-name> 

18. Create a new connection to a remote repository.

Add a new remote repository URL to your local repo using git remote add <name> <url>.

bash
git remote add <name> <repository-url> 

19. Push the committed changes to a remote repository.

Upload your local commits to a remote repository using git push <remote> <branch>.

bash
git push <remote> <branch>

20. Download the content from a remote repository:

Fetch and integrate changes from a remote repository into your local branch using git pull.

bash
git pull <remote>

21. Clean up unnecessary files and optimize the local repository.

Remove unnecessary files and optimize the repository’s data storage with git gc.

bash
git gc

22. Temporarily remove uncommitted changes and save them for later use.

Stash your uncommitted changes temporarily with git stash so you can work on a clean state.

bash
git stash

23. Reapply previously stashed changes.

Restore changes you previously saved with git stash using git stash apply or git stash pop.

bash
git stash apply

You can download this cheat sheet as a PDF here: Download Git Cheat Sheet.