New portion of Pro Git book…

git stash – stashes current workspace
git stash list – shows all stashed snapshots
git stash apply stash@{n} [–index] – reverts workspace to stashed n-th state, if “–index” restores staged status
git stash branch <branch name> – creates a branch from a stash

Rewriting history
git commit –amend – edits last commit (like small rebasing), do not amend already pushed commits
It is also possible to change multiple commits, reorder commits, squash commits, split commits and make filter-branch

Debugging with git
git blame – L n1, n2 <file name> – shows who, when, why has changed source code from n1 to n2 line of file
git bisect – binary search for a bug

Today’s portion of Pro Git book summary

Referencing previous commits
git reflog – shows the places of HEAD
git show <branch name>@{n} – where n is a number of commit
git show <branch name>^n – parent/previous commit, or n-th parent of specified commit
git show <branch name>~n – parent/previous commit, or n-th parent of parent of parent … of specified commit

Commit ranges
git log <commit pointer>..<commit pointer> – two dots shows all commits between one pointer and common commit for two branches pointed by these two pointers
git log <commit pointer>…<commit pointer> – three dots – all commits between these two pointers

Simple guide to start with Git/GitHub

My today’s post about simple actions that should be performed by Git users to initialize local environment for working with GitHub hosting.

Prerequests: there is valid GitHub user’s account which is added as collaborator to some repo.

Actions to init:

  1. Install Git (, create SSH keys. Refer here.
  2. Create local folder for repo
  3. Run Git command prompt and navigate into prepare directory
  4. Run git init command
  5. Run git remote add <remote name> <remote link> command, <remote name> it is just a simple alias word (choose any), <remote link> it is SSH link for your repo (take it from GitHub).
  6. Run git pull <remote name> master command – it will bring all repo’s content locally

Actions to deliver stuff:

  1. Add/modify some file/directory
  2. Run git add . command to add all changes
  3. Run git commit –a –m “<commit comment>” to commit your changes
  4. Run git push <remote name> master to deliver your changes
  5. In case you see “! [rejected]        master -> master (non-fast-forward)” this means someone already committed some changes into this branch, so you need to update your local Git with new changes and only after this to deliver new one. Run git pull <remote name> master, after this repeat git push <remote name> master.

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)

Hello world!

Hi, All

My name is Dmitry Krinitsyn, I am software developer.

Will add some info here soon…