All of the most common Git commands
A quick rundown of all of the most common Git commands and their function.
Initialises a new git repository inside the current working directory
git init
Shows any untracked or modified files that need to be added
git status
Adds specific files to your staging area
git add filename dir/filename2 filename3
Adds all files to your staging area
git add .
Checks differences between your working directory and your staging area
git diff filename
Stores all changes in your staging area permanently in the repository
git commit -m "put a commit message here"
Shows the commit history
git log
Shows the current head commit
git show HEAD
Resets a file in the working directory to look like it did in the head commit
git checkout HEAD filename
Resets a file in your staging area to look like it did in the head commit
git reset HEAD filename
Sets head to a previous commit using the last 7 characters from the desired commit sha (from the commit history)
git reset 7sha
Shows the current branch
git branch
Creates a new branch
git branch branch_name
Switches to a different local branch
git checkout branch_name
Merges another local branch into the current branch
git merge branch_name
Deletes a local branch
git branch -d name
Makes a local copy of the remote project with the remote path from GitHub
git clone remote_path_here new_folder_name
Shows the current projects remote repositories
git remote -v
Fetches changes from the remote but DOES NOT merge them
git fetch
Merges the fetched branch (e.g. origin master) into the current local branch
git merge origin/master
Pushes the commits from a local branch up to the remote (e.g. origin)
git push origin branch_name
Renames the local master branch and pushes it up to the remote (e.g. origin)
git push origin master:new_branch_name