git_2
Master Git with our comprehensive cheat sheet. Find essential commands for repository management, configuration, and remote operations. Your go-to Git reference.
Git Cheat Sheet
Git Commands for Version Control
Git is a distributed version control system that is essential for modern software development. This cheat sheet provides a quick reference for commonly used Git commands, categorized for easy access. Whether you're initializing a new project, managing branches, or collaborating with a team, these commands will help you navigate your Git workflow efficiently.
Repository Management Commands
Command | Description |
---|---|
git init |
Initialize a new Git repository in the current directory. |
git clone <url> |
Clone a remote repository to your local machine. |
git status |
Show the current status of the working directory and staging area. |
git add <file> |
Add a specific file or changes in the working directory to the staging area. Use git add . to add all changes. |
git commit -m <message> |
Record the staged changes to the repository with a descriptive commit message. |
git push |
Upload local commits to the remote repository. |
git pull |
Fetch changes from the remote repository and merge them into the current branch. |
git fetch |
Download commits, files, and refs from a remote repository without merging. |
git merge <branch> |
Integrate changes from a specified branch into the current branch. |
git branch |
List all local branches. |
git branch <branch> |
Create a new branch. |
git checkout <branch> |
Switch to a different branch. |
git checkout -b <branch> |
Create a new branch and switch to it immediately. |
git branch -d <branch> |
Delete a local branch that has been merged. Use -D to force deletion. |
git log |
Display the commit history of the current branch. |
git diff |
Show the differences between the working directory and the staging area, or between commits. |
git blame <file> |
Show the revision and author who last modified each line of a file. |
git reflog |
Show a log of changes to HEAD and branch references. Useful for recovering lost commits. |
git reset --hard <commit> |
Reset the current HEAD to a specific commit, discarding all changes after it. Use with caution. |
git revert <commit> |
Create a new commit that undoes the changes introduced by a specified commit. |
git stash |
Temporarily store uncommitted changes in the working directory to switch branches or perform other tasks. |
git stash pop |
Apply the most recently stashed changes back to the working directory and remove them from the stash list. |
git tag <tag> |
Create a lightweight tag for the current commit. Use -a for annotated tags. |
Git Configuration Settings
Command | Description |
---|---|
git config --global user.name <user> |
Set the global username for commits. This is required for Git to identify you. |
git config --global user.email <email> |
Set the global email address for commits. This is also required for identification. |
git config --global core.editor <editor> |
Specify the default text editor that Git will use for commit messages and other interactive operations. |
git config --global color.ui auto |
Enable colored output for Git commands in the terminal, improving readability. |
Remote Repository Management
Command | Description |
---|---|
git remote add <repository> <url> |
Add a new remote repository connection, typically to a platform like GitHub, GitLab, or Bitbucket. |
git remote -v |
List all configured remote repositories and their corresponding URLs. |
git remote show <repository> |
Display detailed information about a specific remote repository, including its branches and tracking configuration. |
git remote rename <repository> <new_repository> |
Change the name of an existing remote repository. |
git remote remove <repository> |
Remove a connection to a remote repository. |
Understanding and utilizing these Git commands effectively is crucial for any developer. For more in-depth information, refer to the official Git documentation.