Guest User

Untitled

a guest
Aug 17th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. # Github Notes
  2. Notes for some of the common but complicated things I do in git.
  3. All in one place so that I can copy and paste them!
  4.  
  5. ## Commit Triangle
  6. When setting up a new local repo follow these steps to create a triangle that
  7. makes pull requests and other 'GitHub' specfic tasks easier to handle.
  8.  
  9. ```bash
  10. # This is the main repo such as git@github.com:OpenLiberty/open-liberty.git
  11. git clone [repo]
  12. ```
  13. In GitHub fork the repo you want to work on
  14. ```bash
  15. # forked-repo is YOUR fork such as git@github.com:KyleAure/open-liberty.git
  16. git remote add my_fork [forked-repo]
  17.  
  18. # Set git to PUSH to your fork
  19. git config remote.pushdefault my_fork
  20. git config push.default simple
  21.  
  22. # Ensure that you now have origin and my_fork set up
  23. # my_fork git@github.com:KyleAure/open-liberty.git (fetch)
  24. # my_fork git@github.com:KyleAure/open-liberty.git (push)
  25. # origin git@github.com:OpenLiberty/open-liberty.git (fetch)
  26. # origin git@github.com:OpenLiberty/open-liberty.git (push)
  27. git remote -v
  28.  
  29. # Checkout master branch locally
  30. git checkout -b master origin/master
  31.  
  32. # Get any updates and ensure you are up to date
  33. git pull
  34. git push
  35. ```
  36.  
  37. ## Create a New Branch
  38. Used for creating a new branch with special settings if desired
  39.  
  40. ```bash
  41. # Switch to master or integration branch if you are not already there.
  42. git checkout [master]
  43.  
  44. # Make sure master is up to date with origin
  45. git pull
  46.  
  47. # Checkout a new branch.
  48. # Existing-branch is optional if you want to branch off of something other than master
  49. git checkout -b {issue-num}[branch-name] {existing-branch}
  50. ```
  51.  
  52. ## Amend Commit
  53. Commands to amend a commit when the changes are so small that they do not
  54. deserve their own commit. Also useful when making review changes so it
  55. looks like you got it correct the first time :D.
  56.  
  57. ```bash
  58. # Add files like usual by replacing file-name with the file you want to add
  59. # Optionally just use -u for all tracked files or . for all files.
  60. git add [file-name] {-u} {.}
  61.  
  62. # Commit your added files an an amend
  63. git commit --amend
  64.  
  65. # Push amendments to origin
  66. # Optional -f if rewritting history
  67. git push {-f}
  68.  
  69. # Check that you status is "up-to-date"
  70. git status
  71. ```
  72. ## Logging changes
  73. Useful for seeing what is happening with your repo and where your current branch/commit lies
  74.  
  75. ```bash
  76. # For a tree view of where your local changes lie with origin
  77. git log --all --graph --decorate --oneline --simplify-by-decoration
  78.  
  79. # For seeing commits made to origin
  80. # Optionally you can add how many days you want to go back
  81. git log origin/master --author=kyleaure {--since=10days}
  82. ```
  83.  
  84. ## Rewritting History
  85. Useful for situations where you want to combine local commits into one when pushed to origin
  86.  
  87. ```bash
  88. # Get the latest changes to origin
  89. git fetch
  90. ```
  91. Now we are goinng to use an interactive rebase. Rebase rewinds your local
  92. commits, moves your brach up to where master is now. Then attempts to
  93. re-play your commits on top. The {-i} tag makes this interactive so that before
  94. the re-play you can make changes to your commits.
  95.  
  96. ```bash
  97. git rebase origin/{master} -i
  98. ```
  99.  
  100. The interactive interface looks like this:
  101.  
  102. ```
  103. pick xxxx
  104. pick xxxx
  105. pick xxxx
  106.  
  107. # Rebase e227d91..7268d61 onto e227d91 (1 command)
  108. #
  109. # Commands:
  110. # p, pick = use commit
  111. # r, reword = use commit, but edit the commit message
  112. # e, edit = use commit, but stop for amending
  113. # s, squash = use commit, but meld into previous commit
  114. # f, fixup = like "squash", but discard this commit's log message
  115. # x, exec = run command (the rest of the line) using shell
  116. # d, drop = remove commit
  117. #
  118. # These lines can be re-ordered; they are executed from top to bottom.
  119. #
  120. # If you remove a line here THAT COMMIT WILL BE LOST.
  121. #
  122. # However, if you remove everything, the rebase will be aborted.
  123. #
  124. # Note that empty commits are commented out
  125. ```
  126. This will allow you to rewrite history by squashing, editing commit messages, etc.
  127. Once you have chosen how you want to edit history press `esc` and then type `:wq`
  128.  
  129. At this point if there are merge conflics (which is always a posibility when rebasing)
  130. you will need to resolve those. After the rebase is finished:
  131.  
  132. ```bash
  133. # Attempt a regular push first. Since we are rewriting history --force will most like be necessary.
  134. git push {-f}
  135. ```
Add Comment
Please, Sign In to add comment