Git commands for beginners

Recently I started using Git to manage my projects. Naturally I keep forgetting commands, so for not to google each time, I created a list here. Will be updating it as I go.

Command Flags Description
git init initialize new git repository in current folder
git add “stages” files, tells git to track this files, only added files can be commited
git add <file(s)> adds specific files
. adds all files in current folder and sub-folders
-u adds already tracked files which have been modified and removes deleted files
git status gives status of the current folder, untracked files etc.
git commit commits (saves version of) files that have been staged (with git-add)
-a commits all tracked files
-m ".." commits with message in "", not opening editor
git log shows detailed information about commits
git apply to apply a patch
-v "verbose" flag - will show results in the command line
-R reverts specified patch
git clone url folder copying remote repository to your computer
git pull where (e.g. origin master) pulles latest changes from remote repository
git push where (e.g. origin master) pushes your changes to remote repository
git branch -a shows all branches
-r shows only remote branches
git remote show origin shows info about remote
git stash saves work-in-progress changes so you could come back to them later more info
list shows list of saved stashes
apply reapply changes from the latest saves stash
apply reapply changes from specific stash e.g. stash@{2}
drop delete stash e.g. stash@{2}

Reference

Official Git website

Git Community book

Getting good with Git ebook by Andrew Burgess

Git is a version control system used by Drupal.org, so some reading for Drupal contributors – Git documentation on Drupal.org

#archive