Basic Git. https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf http://mislav.uniqpath.com/2010/07/git-tips/
Configure user information for all local repositories.
git config --global user.name "[name]"
Sets the name you want atached to your commit transactionsgit config --global user.email "[email address]"
Sets the email you want atached to your commit transactionsgit config --global color.ui auto
Enables helpful colorization of command line outputgit commit --author="Name <email>" -m "whatever"
git init [project-name]
Creates a new local repository with the specified namegit clone [url]
Downloads a project and its entire version historygit status
Lists all new or modified files to be commitedgit status -sb
Short status outputgit status -u
Show untracked filesgit diff
Shows file differences not yet stagedgit diff --word-diff
Diff by highlighting inline word changes instead of whole linesgit diff [file/folder]
Shows the modifications to the specified file/foldergit add [file|folder|.|wildcard]
Snapshots the file in preparation for versioning, wildcards allowed (*.txt)git diff --staged
Shows file differences between staging and the last file versiongit reset [file]
Unstages the file, but preserve its contentsgit commit -m "[descriptive message]"
Records file snapshots permanently in version historygit remote add origin https://github.com/user/repo.git
Add a remote with name origin for the urlgit remote -v
View remotesgit remote rename origin destination
Rename remote origin to destinationgit remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
Change URL of a remotegit remote rm destination
Remove remote destinationgit checkout -b test <name of remote>/test
Checkout remote branch into localgit branch
Lists all local branches in the current repositorygit branch [branch-name]
Creates a new branchgit checkout [branch-name]
Switches to the specified branch and updates the working directorygit checkout -b [branch_name]
Create a new brach and switch to itgit merge [branch]
Combines the specified branch’s history into the current branchgit branch -d [branch-name]
Deletes the specified branchgit checkout -t origin/feature
Easily track a remote branch from someone elsegit push origin --delete <branchName>
Delete remote branchgit rm [file]
Deletes the file from the working directory and stages the deletiongit rm -r [folder]
Delete recursively the folder and its filesgit rm --cached [file]
Removes the file from version control but preserves the file locallygit mv [file-original] [file-renamed]
Changes the file name and prepares it for commitShelve and restore incomplete changes.
git stash
Temporarily stores all modified tracked filesgit stash pop
Restores the most recently stashed filesgit stash list
Lists all stashed changesetsgit stash drop
Discards the most recently stashed changesetgit log
Lists version history for the current branchgit log --oneline --decorate
Show branches, tags in git loggit log --follow [file]
Lists version history for a file, including renamesgit diff [first-branch]...[second-branch]
Shows content differences between two branchesgit show [commit]
Outputs metadata and content changes of the specified commitgit diff --name-status
Shows only the name of the changed filesgit log --pretty=format:"%h%x09%an%x09%ad%x09%s"
Show author and dategit show @:path/to/file > path/to/file.old
Get the file from other commit (has to be forward slash /
)git reset [commit]
Undoes all commits afer [commit], preserving changes locallygit reset --hard [commit]
Discards all history and changes back to the specified commitgit fetch [bookmark]
Downloads all history from the repository bookmarkgit merge [bookmark]/[branch]
Combines bookmark’s branch into current local branchgit push [alias] [branch]
Uploads all local branch commits to the remote alias in the specified branchgit push -u origin master
Push a branch and automatically set tracking (link between a local and remote branch; git push will by default push all branches that have the same name on the remote)git pull
Downloads bookmark history and incorporates changes (fetch + merge)git pull --rebase
Pull with rebase instead of mergeBecause branch merges in git are recorded with a merge commit, they are supposed to be meaningful—for example, to indicate when a feature has been merged to a release branch. However, during a regular daily workflow where several team members sync a single branch often, the timeline gets polluted with unnecessary micro-merges on regular git pull. Rebasing ensures that the commits are always re-applied so that the history stays linear. More about rebasing vs merging here and here.