Git cheat sheet

Per definition, Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Even though git is easy to learn, the problem is that people introduce the powerful features of Git that only a few percentages of developers will ever use. Below, you are going to find the most used git commands grouped by their functionality

GIT BASICS

Git commandDescription
git init <directory>Create empty Git repo in specified directory. Run with no arguments to initialize the current directory as a git repository.
git clone <repo>Clone repo located at onto local machine. The original repo can be located on the local filesystem or on a remote machine via HTTP or SSH.
git config user.name <name>Define author name to be used for all commits in the current repo. Devs
commonly use –global flag to set config options for the current user.
git add <directory>Stage all changes in for the next commit. Replace with a to change a specific file.
git commit -m “<message>”Commit the staged snapshot, but instead of launching a text editor, use it as the commit message.
git statusList which files are staged, unstaged, and untracked.
git logDisplay the entire commit history using the default format.
For customization see additional options.
git diffShow unstaged changes between your index and
working directory
Git basic commands table

GIT UNDO CHANGES

Git commandDescription
git revert <commit>Create a new commit that undoes all of the changes made in, then apply it to the current branch.
git reset <file>Remove from the staging area, but leave the working directory unchanged. This unstages a file without overwriting any changes.
git revert <commit>Shows which files would be removed from the working directory.
Use the -f flag in place of the -n flag to execute the clean.
Git undo changes commands table

GIT BRANCHES

Git commandDescription
git branchList all of the branches in your repo. Add an argument to create a new branch with the name.
git checkout -b <branch>Create and check out a new branch named. Drop the -b flag to checkout an existing branch.
git merge <branch>Merge into the current branch.
Git branches command table


REMOTE REPOSITORIES

git remote add <name> <url>Create a new connection to a remote repo. After adding a remote, you can use as a shortcut for in other commands.
git fetch <remote> <branch>Fetches a specific , from the repo. Leave off to fetch all remote refs.
git pull <remote>Fetch the specified remote’s copy of the current branch and
immediately merge it into the local copy.
git rebase -i <base>Interactively rebase current branch onto . Launches editor to enter commands for how each commit will be transferred to the new base.
git pull –rebase <remote>Fetch the remote’s copy of current branch and rebases it into the local
copy. Uses git rebase instead of merge to integrate the branches.
git push <remote> <branch> Push the branch to , along with necessary commits and objects. Creates named branch in the remote repo if it doesn’t exist.
git push <remote> –forceForces the git push even if it results in a non-fast-forward merge. Do not use
the –force flag unless you’re absolutely sure you know what you’re doing
git push <remote> –allPush all of your local branches to the specified remote.
git push <remote> –tagsTags aren’t automatically pushed when you push a branch or use the
–all flag. The –tags flag sends all of your local tags to the remote repo.


Enjoyed this post? Subscribe to my YouTube channel for more great content. Your support is much appreciated. Thank you!


Check out my Udemy profile for more great content and exclusive learning resources! Thank you for your support.
Ervis Trupja - Udemy



Enjoyed this blog post? Share it with your friends and help spread the word! Don't keep all this knowledge to yourself.