💡 Basic Git commands used in a professional environment.
Breakdown
The Most Used
git init - initialise a Git repository, ergo, let Git know that it should start tracking changes in that foldergit add . - track all changed files, preparing to be committedgit commit -m "message here" - commit files with a messagegit push -u origin "branchName" - push to remote for the first timegit stash - temporarily saves changes, often used when the changes are not ready to be committed yet but you need to check out another branchgit checkout -b "newBranchName" - to create a new local branch and switching to itgit switch "existingBranchName" - to switch between existing branchesgit pull - fetch changes from remote repositorygit merge "branchName" - merge the named branch with the current oneUndo last commit locally and remotely// undo last commit in your local branch
git reset --hard HEAD~1
// push remote branch forward to match the local one
git push -f
Extra
git status - state of the current working treegit log - spits out a list of all the commitsgit stash list - list all the stashesgit stash drop - delete the latest stashgit config:// set the username
git config --global user.name "username"
// set the email address
git config --global user.email "email@example.com"
Resources