First (and biggest one) piece of summary of Pro Git Book

local copy of all history
full files for each check-in, not delta-tree
stage – snapshot of file for commit
get repository – git init or git clone
state of file – untracked, tracked (unmodified, modified, staged)

git status – look around
git add – add new files to be tracked, or to state already tracked but changed file
.gitignore – ignore pattern
git diff – shows unstaged changes, git diff –cached (–staged, for later 1.6.1 version of git) – shows difference between staged files and last commit

git commit (-a skipping staging step)
git rm (-f to remove modified file) – remove files from repo and from working directory, (–cached – to make file untrackable, but not to remove from hard drive)
git mv – move file, but it is equal to add+rm file

git log – view commits log (-2 – option shows only two last commits)
page 23
git log –stat shows how many lines were changed by each commit
git log –pretty formats an output log information
git log –graph draws simple commit/branch/merge graph
git log limiting option -<n>, –since, –until, –author, –commiter

git commit –amend – add some changes to previous commit
git reset HEAD <filename> – unstaging some file
git checkout — <filename> – overwriting some file with last committed state.

git remote -v – see remote server for some workspace
git remote add <name for remote> <URL> – adding remote
git fetch <remote name> – fetches all data from remote to local repo, but not merge into workspace
git push <remote name> <branch name> – push our local repo into remote repo. In case conflicts, inefficient write permit ions for remote repo, or inconsistent state of remote (you are not sync with last update on remote) – push will be rejected
git remote show <remote name> – state of remote repo (new, pushed, pulled, tracked branches) is shown
git remote rename <old remote name> <new remote name>
git remote rm <remote name>
Tags of two types: lightweight (pointer on specific commit) and annotated (real git object with name, mail, comment, can be signed with private key)
git tag [-l <string pattern>] – lists all tags in alphabetical order (pattern for filtering is optional)
git tag -a [-s -m] <tag name> [existed untagged commit id] – annotated tag
git tag – lw tag
git show <annotated tag name> – shows details of a tag
git tag -v (<tag name>|–tags) – verify by public key some tag (you need to have this key in keyring)
git push origin <tag name> – pushes tag into remote repo (until this it is local entity), tags will be accessible by any person how pulls this repo later.

git can have autocomplition.
aliases (short name) for commands can be created.

git branch <branch name> – creates a branch
git checkout <branch name> – switch current branch on selected one, moves HEAD onto selected.
git checkout -b <branch name> – creates and checkouts some branch
git branch -d <branch name> – deletes some branch
for merging two branches new snapshot could be created

<<<<<<< HEAD:<file name>
we merge into here
=======
we merge from here
>>>>>>> <branch name>:<file name>

After resolving of all conflicts we need to stage (add) a manually merged fie and commit it.
git branch -v – shows all branches with last commit
git branch [–merged|–no-merged] shows merged (good candidates for deleting) and not merged into current one branch
git branch -d – doesn’t delete an unmerged branch, need to use -D (capital) option
git push <remote> <branch> – push some local branch to server, transform it into remote branch
git push <remote> <local branch>:<remote branch> – the same as previous one but in case if remote and local branch are called differentially
git checkout –track <remote>/<branch> – to track some remote branch
git push <remote> :<branch> – delete remote branch

Merge and rebase do actially the same – combines two branches into one. Merge adds all changes from one branch into another by one commit, rebase adds all commits separatelly (history is kept).
git rebase <branch> – rebases the specified branch with currently checked-out
git rebase –onto <branch1> <ancestor btranch2> <ancestor branch3> – rebases branch1 with difference of branch3-branch2

Git protocols:
– local (read/write) – local/shared file system
– SSH (read/write)
– GIT (read)
– HTTP(S) (read/ can be write)

Advertisements

About DmitryKrinitsyn
Software developer and muay thai adept

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: