2

My personal git cheatsheet/reference

>Here is my personal git cheatsheet/reference. Publishing here to be able to access from anywhere, and just in case someone else finds it useful, too.

I keep it as a simple text file, so it is placed here verbatim.

Resources:
http://progit.org/book/

-------

modified -> staged (git add) -> committed (in git db)

See last two commits with diff: git log -p -2
See commits in different formats: git log --pretty=
My git log format: git log --pretty:format:"%h %an (%ar): %s"
gitk shows log in gui (distributed with git)

Modify last commit: git commit --amend

Working with remotes: ----------

git remote add [shortname] [url]

Multiple remotes: branches are available as [shortname]/[branch]
e.g. identra/master

git remote show [remote name]
get remote rename [remote name] [new remote name]

git fetch [remote name]
git pull # -- works on the remote branch the local branch is set to follow
git push [remote name] [branch name]

git remote rm [remote name] # - remove reference to remote repo

Tagging

git tag # list tags
git tag -l [pattern] # list tags that match the pattern
git tag -a [tag] # add a new tag
git tag -a [tag] [short/long commit hash] # add new tag at a previous commit

Tags are not pushed to remote servers, unless you do
git push [remote name] [tag name]
git push [remote name] --tags # push all your tags


Branching -----------------------------

A branch is simply a pointer to a commit, which gets updated as a new commit
is made on top of the commit pointed by the branch (each commit has a pointer
to its predecessor).

In other words, a new commit always points to the HEAD at the time it is
committed as its previous commit (then HEAD gets updated to point to the
last commit).

Nice illustration here:

git branch [branch name] # create new branch

A special pointer HEAD points to the local branch you are working on.

git checkout [branch name] # update working copy to given branch, and set HEAD
git checkout -b [branch name] # create new branch and update HEAD with one cmd

git merge [branch name] # merge given branch to branch pointed by HEAD

git branch -d [branch name] # remove a branch

Pushing pulling branches:

git fetch [branch name]
git push [remote name] [branch name]
git push [remote name] :[branch name] # remove a remote branch

Rebasing:

Resource: http://progit.org/book/ch3-6.html

Rebasing replays changes from one line of work onto another in the order they
were introduced, whereas merging takes the endpoints and merges them together.

git rebase [target branch]

Rebase creates a linear history, by applying the diffs from the branching
point of the branch pointed by HEAD, to the given branch in rebase cmd.

2 Comments

  1. >Güzel gözüküyor. Ancak belirtmeliyim ki kullanmadım.

    Şu sıralarda bir "konsola dönüş" sendromu yaşıyorum. O yüzden grafik araçlardan biraz uzağım. :)

Leave a Reply to Celaleddin Subaşı Cancel reply

Your email address will not be published. Required fields are marked *