Friday, October 25, 2013

Github cheat sheet

HEAD - pointer to latest commit
git diff <source_branch> <target_branch> - changes between 2 branches
git diff HEAD - changes with latest commit
git diff --staged - diff with staged files
git reset <file> - unstage <file>

Branch - the copy of project
git branch <branch_name> - creates branch <branch_name>
git checkout <branch_name> - switch branch to <branch_name>
git branch -d <branch_name> - delete <branch_name> branch

Merge - copy changes to current branch
git checkout <branch_name> - now we'r in the <branch name>
git merge <other_branch_name> - merge <other_branch_name> changes into <branch_name>

Update your local copy to latest:
git pull
Creating tag:
Tag is a software release (like in SVN)
git tag 1.0.0 b01a419cff
The b01a419cff is a commit id.

If something went wrong, and you need to replace changes:
git checkout -- <file_name> - replaces changes with the last content in HEAD.

If you want to drop all local changes and commits:
You need to fetch the latest history from remote repo and point local master branch at it
git fetch origin
git --hard origin/master

How git works:
1. Changes in local repo
git add --all
2. Changes in Index (staged)
git commit -m "Adding all files"
3. Changes in HEAD (commited, but still not in remote repo)
git push origin <branch_name> (git push origin master)
4. Now changes pushed to remote repository (master or other branch)

Usefull commands: 
Launches git GUI:

gitk

Information from:
http://try.github.io
http://rogerdudler.github.io/git-guide/

No comments:

Post a Comment