From 8c9071a41c037f0b78414ae061c8628d104cff4b Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sun, 20 Jul 2014 05:44:15 -0700 Subject: [PATCH] git in a few command --- Git-survival-guide.md | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Git-survival-guide.md diff --git a/Git-survival-guide.md b/Git-survival-guide.md new file mode 100644 index 0000000..03631ab --- /dev/null +++ b/Git-survival-guide.md @@ -0,0 +1,44 @@ +There is a lots of guide/docs on internet but there are too big and confusing. You will find here a mini guide to use git with a minimal number of command and parameters. You won't find any details or explication of git internal mechanism here. + +## Remote Transfer or how to communicate with the world +* Get a fresh repository: git clone `` +* Update current repository to latest: git fetch -v +* Update current repository with commit from a fork: git fetch -v `` `` +* Send your new commit to the remote: git push + +## Commit or how to communicate with your local repository +* staged your change: git add/rm -p `` +* commit your change: git commit +* uncommit previous commit: git reset --soft HEAD~1 +* unstage your change: git reset HEAD -- +* discard your change **forever**: git checkout -p -- `` + +## Stash or how to save your precious work +Stash is very useful. For example, your will use it before/after (push/pop) merge/rebase action +* Push pending update on the stack: git stash +* Get back your update: git stash pop +* view content of your stash: git stash show -p `stash@\{0\}` + +## Rebase or how to screw the history +**Never** rebase commits that were pushed remotely. Rebase can be used to improve your current patch set, or to fast-forward-merge after a fetch. +* The rebase command: git rebase -i +* Cancel it : git rebase --abort +* Resolve conflict: git mergetool `` +* Continue rebase: git rebase --continue + +## Branch or how to separate your work by feature +Please note that master is actually the default branch +* List branches: git branch -v +* Switch to another branch: git checkout `` +* Creates: git branch `` +* Delete branches: git branch -d `` +* Set the base reference of the branch (for rebase): git branch --set-upstream-to=`` `` + +## Branch use case +Let's say you want to rebase your current branch topic-v1 to topic-v2 with new addition. Note topic-v1 could also be master too. +* Go to current branch: git checkout topic-v1 +* Create a new one: git branch topic-v2 +* Go into the new branch: git checkout topic-v2 +* Set the reference: git branch --set-upstream-to=origin/master topic-v2 +* Rebase: git rebase -i +* ... \ No newline at end of file