Git is a free and open-source distributed version control system that’s responsible for tracking file changes to facilitate collaborative work with others. This Cheat Sheet features the most important and commonly used Git Commands for easy reference.
Better styled PDF and Markdown formats of this Cheat Sheet are available on GitHub at the following link:
The YouTube Channels in both English (En) and French (Fr) are now accessible, feel free to subscribe by clicking here.
Setup
Configuring user information used across all repositories:
git config --global user.name "[firstname lastname]"
: Sets a name that is identifiable for credit or ownership of change within the version historygit config --global user.email "[valid-email]"
: Sets an email address that will be associated with each history marker
The same configs can be done for a specific project with the "--local"
option that applies to the current repository only.
Basic Commands
git init
: Initializes a new Git repositorygit clone <url>
: Clones an existing repository into a new directorygit add <file>
: Adds changes to the staging areagit commit -m "<message>"
: Commits changes to the local repository with a messagegit push
: Pushes committed changes to a remote repositorygit pull
: Pulls changes from a remote repositorygit fetch
: Fetches changes from a remote repository
Branching and Merging
git branch
: Lists all branches in the repositorygit branch <name>
: Creates a new branch with the given namegit checkout <branch>
: Switches to the specified branchgit merge <branch>
: Merges the specified branch into the current branchgit rebase <branch>
: Rebase current branch onto specified branch
Viewing History
git log
: Shows a log of all commitsgit log --oneline
: Shows a compact log of all commitsgit diff <commit>..<commit>
: Shows the differences between two commitsgit blame <file>
: Shows who last modified each line of a file
Undoing Changes
git reset <file>
: Unstages changes in the given filegit reset <commit>
: Resets the current branch to the specified commitgit revert <commit>
: Creates a new commit that undoes the changes in the specified commit
Collaborating with Others
git remote add <name> <url>
: Adds a new remote repository with the given name and URLgit remote -v
: Lists all remote repositoriesgit pull --rebase
: Pulls changes from a remote repository and rebases local changes on top of themgit push <remote> <branch>
: Pushes the specified branch to the specified remote repository
———————
We have just started our journey to build a network of professionals to grow our free knowledge-sharing community that’ll give you a chance to learn interesting things about topics like cloud computing, software development, and software architectures while keeping the door open to more opportunities.
Does this speak to you? If YES, feel free to Join our Discord Server to stay in touch with the community and be part of independently organized events.
———————
Thanks for reading this article. Like, recommend, and share if you enjoyed it. Follow us on Facebook, Twitter, and LinkedIn for more content.