blog - re construct the blog files
[blog.git] / posts / git-note.org
diff --git a/posts/git-note.org b/posts/git-note.org
new file mode 100644 (file)
index 0000000..cd11c5a
--- /dev/null
@@ -0,0 +1,60 @@
+#+TITLE: Git Note
+#+AUTHOR: Peng Li
+#+EMAIL: seudut@gmail.com
+#+DATE: 2016-12-18
+
+* Git Note
+** Update an forked repo on  Github
+See [[http://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository]]
+#+BEGIN_SRC sh :results output replace
+  # Add the remote, called it "upstream", which is the original repo forked
+
+  git remote add upstream https://github.com/whoever/whatever.git
+
+  # Fetch upstream
+
+  git fetch upstream
+
+  # switch to master
+
+  git checkout master
+
+  # rebase all commit in upstream
+
+  git rebase upstream/master
+
+  # push the new commit
+
+  git push origin master
+#+END_SRC
+
+** Move branch pointer to commit
+Ususally, we create a branch for some bug fix. If it is a regress issue, we oftern need to rollback to some commit to fix the 
+bad commit. In this case, we need to move the branch to another commit
+[[http://stackoverflow.com/questions/5471174/git-move-branch-pointer-to-different-commit-without-checkout]]
+
+#+BEGIN_SRC sh :results output replace
+  git branch -f branch-name COMMIT
+#+END_SRC
+
+** Track local branch to remote branch
+Sometime, we enter the issue =no upstream is configured for master=, It is because of local branch tracking is not configured
+If you input ~git pull~, it hints the error
+#+BEGIN_EXAMPLE
+  peli3@[~/Private/blog]>> git pull                                                         ±[••][master]
+  There is no tracking information for the current branch.
+  Please specify which branch you want to merge with.
+  See git-pull(1) for details.
+
+      git pull <remote> <branch>
+
+  If you wish to set tracking information for this branch you can do so with:
+
+      git branch --set-upstream-to=origin/<branch> master
+#+END_EXAMPLE
+
+#+BEGIN_SRC sh :results output replace
+  git branch --set-upstream-to=origin/master master
+#+END_SRC
+
+