Git Cheatsheet r2v1 PDF
Git Cheatsheet r2v1 PDF
Table of contents
1. The basics. . . . . . . . . . . . . . . . . . . . . . . . . . . 1 4. Git CLI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2. Installation. . . . . . . . . . . . . . . . . . . . . . . . . . 1 5. Quickstart using Git. . . . . . . . . . . . . . . . . 4
3. Git command sequence. . . . . . . . . . . . . . 2 6. About the author. . . . . . . . . . . . . . . . . . . . 6
The basics
Git is a free and open source distributed version control system designed to handle
everything from small to very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses
SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local
branching, convenient staging areas, and multiple workflows.
Installation
Windows https://windows.github.com
Mac https://mac.github.com
# set a name that is identifiable for credit when reviewing version history
$ git config --global user.name "[firstname lastname]"
# set an email address that will be associated with each history marker
$ git config --global user.email "[valid-email]"
# set automatic command line coloring for Git for easy reviewing
$ git config --global color.ui auto
1
Git commands sequence
Git CLI
Create
# Clone an existing repository
$ git clone https://github.com/bparees/openshift-jee-sample.git
Local changes
# Changed files in your working directory
$ git status
2
Commit history
# Show all commits, starting with newest
$ git log
# Download all changes from <remote>, but don‘t integrate into HEAD
$ git fetch <remote>
3
Merge & rebase
# Merge <branch> into your current HEAD
$ git merge <branch>
# Abort a rebase
$ git rebase --abort
# Use your editor to manually solve conflicts and ( after resolving) mark
file as resolved
$ git add <resolved-file>
$ git rm <resolved-file>
Undo
# Discard all local changes in your working directory
$ git reset --hard HEAD
# Reset your HEAD pointer to a previous commit and discard all changes
since then
$ git reset --hard <commit>
# Reset your HEAD pointer to a previous commit and preserve all changes as
unstaged changes
$ git reset <commit>
4
2. Do your stuff on files
# Update your codes or add new files or delete some of them via your
favorite editor
$ vi hellowWorld.java
…
Change your codes or contents
…
Save and Quit <wq>
# If you need to add a specific file to your staging, you have to describe
the file name explicitly
$ git add <filename>
5
7. Inspect the commit history
# The “git log” command lists all the commits that were saved in
chronological order. This allows you to see which changes were made in
detail and helps you comprehend how the project evolved
$ git log
commit 6a8110589c25eac8acd7223d2bf91995c0b72db8
Author: Daniel Oh <doh@redhat.com>
Date: Fri Mar 24 13:27:03 2017 -0400
Update Zipkin to 0.1.9
commit 40380a55163a7e93366c01e37d1d0ad5a3afc848
Author: Daniel Oh <doh@redhat.com>
Date: Thu Mar 23 21:44:09 2017 -0400
Remove the need to adjust SCC
# Publish local changes on a remote
$ git push
@danieloh30
https://www.linkedin.com/in/daniel-oh-083818112