cd11c5ad72d084240b1af9ee78491beb1d31ea3d
[blog.git] / posts / git-note.org
1 #+TITLE: Git Note
2 #+AUTHOR: Peng Li
3 #+EMAIL: seudut@gmail.com
4 #+DATE: 2016-12-18
5
6 * Git Note
7 ** Update an forked repo on  Github
8 See [[http://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository]]
9 #+BEGIN_SRC sh :results output replace
10   # Add the remote, called it "upstream", which is the original repo forked
11
12   git remote add upstream https://github.com/whoever/whatever.git
13
14   # Fetch upstream
15
16   git fetch upstream
17
18   # switch to master
19
20   git checkout master
21
22   # rebase all commit in upstream
23
24   git rebase upstream/master
25
26   # push the new commit
27
28   git push origin master
29 #+END_SRC
30
31 ** Move branch pointer to commit
32 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 
33 bad commit. In this case, we need to move the branch to another commit
34 [[http://stackoverflow.com/questions/5471174/git-move-branch-pointer-to-different-commit-without-checkout]]
35
36 #+BEGIN_SRC sh :results output replace
37   git branch -f branch-name COMMIT
38 #+END_SRC
39
40 ** Track local branch to remote branch
41 Sometime, we enter the issue =no upstream is configured for master=, It is because of local branch tracking is not configured
42 If you input ~git pull~, it hints the error
43 #+BEGIN_EXAMPLE
44   peli3@[~/Private/blog]>> git pull                                                         ±[••][master]
45   There is no tracking information for the current branch.
46   Please specify which branch you want to merge with.
47   See git-pull(1) for details.
48
49       git pull <remote> <branch>
50
51   If you wish to set tracking information for this branch you can do so with:
52
53       git branch --set-upstream-to=origin/<branch> master
54 #+END_EXAMPLE
55
56 #+BEGIN_SRC sh :results output replace
57   git branch --set-upstream-to=origin/master master
58 #+END_SRC
59
60