Basic Git Command Line Reference

Git can be difficult to get used to so I made a quick reference guide of the basic, most common commands I use. I normally check the status of the working directory for changes, commit them, and push to the master branch.

Jump to section:
Push an edit to the master branch
Push a specific edited page to the master
Add a new File
Add multiple new files
Undo a staged change
Discard unstaged changes to a specific file
Remove a File from the branch

Push an edit to the master branch

Run git status to displays changes:

git status

Modified pages will display:

modified: _layout/header.html
modified: _posts/hello.html

Commit all (-a) changes with a message (m):

git commit -am "Updated header and hello post"

Push changes to the master branch:

git push

Push a specific edited page to the master

git status

Modified pages will display:

modified: _posts/test.html
modified: _posts/test1.html

Commit and push the specific page with a message:

git commit _posts/test1.html -m "Added content"
git push

Add a new File

After manually adding a file to my project folder, I want to add it to the master branch.

git status

Untracked files will display:

test.html

Add the file to be committed:

git add test.html

Commit with a message and push the file to the master branch:

git commit -m "Added test.html"
git push

Add multiple new files

git status

Untracked files will display:

test.html
test1.html

Add all with capital, "-A". Commit with a message and push:

git add -A
git commit "Added test and test1"
git push

Undo a staged change

E.g. Undo adding a page:

git add test.html

Unstage the commit using reset HEAD and specifying the page:

git reset HEAD test.html

Discard unstaged changes to a specific file

E.g. Edited a file on the branch but decided that I no longer want the edit:

git status

Changes not staged for commit:

modified: test.html

Checkout will delete changes to the file specified:

git checkout test.html

Remove a File from the branch with rm.

git rm test.html
git status

Changes to be committed:

deleted: test.html

Commit all changes with a message and push:

git commit -am "removed test.html"
git push