Git Cheat Sheet
Git is a popular version control system that allows developers to track changes to their code and collaborate with others. It is widely used in the software industry and has become an essential tool for many developers. This "git cheat sheet" is a quick reference guide that lists the most commonly used git commands. It is intended for beginners who are new to git, as well as experienced developers who want a refresher on the basic commands. Whether you are working on a small project with a few collaborators or a large project with a team, git can help you manage your code and keep track of your progress.
Command | Description |
---|---|
git init | Initialize a new Git repository |
git clone <repo> | Clone an existing repository |
git add <file> | Add a file to the staging area |
git commit -m "<message>" | Commit changes with a message |
git branch <name> | Create a new branch |
git checkout <branch> | Switch to a different branch |
git merge <branch> | Merge a branch into the current branch |
git pull | Pull changes from a remote repository |
git push | Push local commits to a remote repository |
git status | View the current status of the repository |
git log | View the commit history |
git reset <file> | Unstage a file |
git diff | View differences between committed versions |
git stash | Stash changes to temporarily shelve them |
git revert <commit> | Revert to a previous commit |
git tag <tagname> | Create a tag to mark a specific commit |
git fetch | Fetch changes from a remote repository without merging them |
git blame <file> | View the commit history for a file |
git cherry-pick <commit> | Apply changes from a specific commit |
git clean -f | Remove untracked files from the repository |
git rebase <branch> | Rebase the current branch onto another branch |
git submodule <repo> | Add a submodule to the repository |
git cherry-pick <commit> | Apply changes from a specific commit |
git clean -f | Remove untracked files from the repository |
git submodule <repo> | Add a submodule to the repository |
git branch -D <branch> | Delete a branch |
git branch -m <newname> | Rename a branch |
git push <remote> --delete <branch> | Delete a remote branch |
git push <remote> <branch> | Push a local branch to a remote repository |
git branch -a | List all local and remote branches |
git checkout -b <branch> | Create and switch to a new branch |
git stash list | View a list of stashes |
git stash apply | Apply the latest stash |
git stash pop | Apply the latest stash and remove it from the stash list |
git stash drop | Remove the latest stash from the stash list |
git stash clear | Remove all stashes from the stash list |
git tag -d <tagname> | Delete a tag |
git push <remote> :<branch> | Delete a remote branch |
git push <remote> --tags | Push all tags to a remote repository |
git tag -v <tagname> | Verify a tag's GPG signature |
git remote -v | List all remote repositories |
git remote add <name> <url> | Add a remote repository |
git remote rename <oldname> <newname> | Rename a remote repository |
git remote remove <name> | Remove a remote repository |
git remote set-url <name> <newurl> | Set the URL for a remote repository |
git submodule init | Initialize submodules in the repository |
git submodule update | Update submodules to the latest commit |
git submodule sync | Synchronize submodule URLs with the parent repository |
git submodule status | View the status of submodules in the repository |
git submodule deinit <repo> | Remove a submodule from the repository |
git submodule foreach <command> | Run a command in each submodule |
git submodule summary | View a summary of changes in submodules |
git config --global user.name "<name>" | Set the user's name for Git commits |
git config --global user.email "<email>" | Set the user's email for Git commits |
git config --global --list | View the user's Git configuration |
git config --global color.ui auto | Enable color output for Git |
git config --global core.editor "<editor>" | Set the default text editor for Git |
git config --global alias.<alias> "<command>" | Set an alias for a Git command |
git config --global --unset <key> | Unset a Git configuration value |
git config --global --replace-all <key> "<value>" | Replace all instances of a Git configuration value |
git config --global credential.helper "<helper>" | Set a credential helper for Git |
git config --global push.default simple | Set the default push behavior for Git |
git config --global merge.conflictstyle diff3 | Set the default merge conflict style for Git |
Printable PDF's
GitHub has a great pdf that you can print out and put on your wall next to your desk. And yes, GitLab has one too.
Popular Git Clients
There are several popular git clients that developers use to interact with git repositories. Some of the most popular ones include:
command line: While not a software client per se, many developers prefer to use the command line interface for interacting with git repositories. This is especially true for advanced users who are comfortable working with the command line and want to have more control over their workflow. The cheat sheet above can be helpful here.
Git for Windows: This is a port of the git command line interface for Microsoft Windows. It includes a GUI for managing git repositories, as well as the git command line tools.
GitKraken: This is a cross-platform git client with a graphical user interface. It is designed to make working with git easier and more intuitive, especially for users who are new to git.
GitHub Desktop: This is a git client developed by GitHub that is available for Windows and macOS. It includes a graphical user interface for managing git repositories, as well as integrations with other GitHub features.
SourceTree: This is a git client developed by Atlassian that is available for Windows and macOS. It includes a graphical user interface for managing git repositories, as well as support for other version control systems such as Mercurial.
Git Facts You May Find Interesting
Git was created by Linus Torvalds in 2005 to manage the development of the Linux kernel. It was designed to be fast, efficient, and distributed, which makes it well-suited for large and complex projects like the Linux kernel.
Git stores its data in a data structure called a "directed acyclic graph" (DAG). This data structure allows git to track the relationships between different versions of a project, as well as the changes that were made in each version.
Git has a rich history of development and has inspired many other version control systems. Some of the most well-known ones include Mercurial, Subversion, and Perforce.
Git is written in the C programming language and is designed to be portable, so it can be compiled and run on a wide range of operating systems.