Git is a very powerful version control and a project managing tool. Every dev has to use git for projects. Below is my git cheatsheat. Below are some basic commands and some settings every developer should know
Basics
git init
for initiating a git repo in a foldergit add
to add file/folder to staging areagit commit
to commit changesgit push
to publish changes to remotegit status
to check status of git repo including staged and unstaged changes
Branches
You can use branches for making a copy of repo, implementing a feature and then merging it back to main branch
git branch
is used for listing all branchesgit branch <branch_name>
is used for creating new branchgit branch -d <branch_name>
is used for deleting a branchgit checkout <branch_name>
to switch to new branchgit merge <merge_into_this>
to merge currently checked out branch to some other branch
Stashes
The git stash
command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy.
This is particularly useful in merge conflicts and syncing forks.
git stash list
shows all stashesgit stash drop
for dropping changesgit stash apply
for applying changesgit stash pop
forgit stash apply + drop
Reverting Commit
git reset --hard HEAD~n
(Doesn’t retain uncommited changes)git reset --soft HEAD~n
(Retains uncommited Changes) where n is the number of commits to be reverted.
Git Configs
You can also use git configs to create your own shortcuts and much more. The one git setting I always use is
- Auto Setting push remote
git config --global --add --bool push.autoSetupRemote true
For Further commands see this cheatsheat