This cheat sheet summarizes my most commonly used git commands, and I will update it periodically.
Initialize
git config --global user.name "Name Username"
git config --global user.email [email protected]
I rarely initialize a repo locally, so I don’t need to use git init
. However, keep in mind that it’s useful for initializing an existing directory as a Git repository
.
Basic commands
git checkout -b <new-branch> # create new branch and switch to it, never work directly on master
git add . # add all files to next commit (stage them)
git status # check files added to commit
git commit -m "commit msg" # commit files to branch
git push # push changes to remote repository
git pull # pull changes pushhd to remote repository
Advanced commands
git revert <commit> # creates NEW commit that reverts changes introduced in specified commit
git rebase <branch> # reapplies commits on the current branch onto the tip of the specified branch