Overview #
This is intended to be a Git quick bites reference. The commands found in this document are commonly used commands for code and repository management. For more detailed explanations and command options please reference Git Docs.
Git Commands #
git add #
git add <file_name>
# stages file(s) or directory for next commitgit add -all
# stages all changed file(s) and directory for next commit
git branch #
git branch
# view current branchgit branch <branch_name>
# create new branchgit branch -d <branch_name>
# delete branch of choice
git clone #
git clone --recurse-submodules <repository>
# important for cloning Hugo repository
git commit #
git commit -m "Message about this commit"
git config #
git config --global user.name "username"
# configure your usergit config --global user.email "[email protected]"
# configure your emailgit config pull.rebase false
# mergegit config pull.rebase true
# rebasegit config pull.ff only
# fast-forward only
git checkout #
git checkout <branch_name>
# change branchesgit checkout -b develop remotes/origin/develop
git fetch #
git fetch <remote> <branch_name>
git merge #
git merge <branch_name>
# merges branch into current working branch
git pull #
git pull
# pull any changes from remote repositorygit pull <remote> <branch_name>
# pull any changes from specific remote branch
git push #
git push <remote> <branch_name>
# pushes branch changes to remote repositorygit push origin --delete <branch_name>
# deletes remote branch
git stash #
# could be considered advanced
git stash
git stash list
git stash pop
git stash apply
git stash apply stash@{n}
git stash drop stash@{n}
git stash clear
Other Commands #
git diff
# used to check the differences in a filegit init
# initialize a new repositorygit log
# view the log of commitsgit status
# check the current status of your repositorygit switch <branch_name>
# switches to desired branch
Common Command Sequence #
# when working with multiple branches
git fetch --all && git branch -a && git checkout -t origin/<branch_name>