git clone Download (clone) a copy of a remote git repository
git log Show the commit log git log -n1 --pretty=format:%h-%ct Show an abbreviated hash code and a unix timestamp of last commit git status This will output some information about the state of the local copy of the cloned repository. It reports the branch name, the number of commits that have not been pushed, a list of files staged for commit, and a list of untracked files.
git branch List all local branches git branch -a List all branches (local and remote) git branch local-branch-name remote-branch-name Make new local branch
git checkout -b local-branch-name remote-branch-name Make new local branch and checkout the branch git checkout local-branch-name
git stash save Use this if you have locally changed files (not yet committed) before you use "git pull" git pull Use this if you have no local commits that have not been pushed git pull --rebase Use this if you have local commits that have not been pushed git stash pop If you stashed local changes before the pull this reapplies your changes
git add [file1 [file2] ...] Mark a file to be committed on next use of commit. The "git status" command will show the added files as staged, and the staged files will not be shown in the output from "git diff". git add --interactive [filespec] Interactively add (stage) files for the next commit git reset <file> Unstage a file so it won't be committed git rm Removes a file (or files) from the list of staged files. For unstaged files the file(s) will be removed from the filesystem and deleted from the remote repository. git commit It usually only commits staged changes if no file names are specified on the command line. Use git add or git rm to stage changes ready for commit. git commit --amend Make changes to a commit that has not been pushed git push [-a] Push recent local commits to the remote git repository
git format-patch [-n] where n is the number of recent commits to make patch files for git am apply patch(es) created by 'format-patch' git am --abort Abort the patching operation and restore the original branch.
git clean [-df] Get rid of files git clean -xdf Don't use ignore files when cleaning the source tree. Useful when it says a merge is required to avoid clobbering some files so it won't change branches. git reset [--hard]
git config [--global] Automatic text file line ending conversion can be set in ~/.gitconfig using "autocrlf = input" under the [core] section. The user name and email to be recorded in commits can be set in the [user] section.
The file .git/config has the URL for the source of the remote repository
After amending a comment for an unpushed commit that was not the HEAD
commit, use the following to fix up the log entry:
git rebase -i HEAD~n
where n refers to the nth commit before the current HEAD commit
git am -3
Will record changes in directory tree (ie. files removed via rm instead of git rm).
core.autocrlf=input (use auto on Windows)
A nifty view of branches, tags, and other refs:
git log –oneline –graph –decorate –all