Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. # The Git presentation
  2.  
  3. ## The ideea
  4. Simulate a simple project migration process
  5.  
  6. Start from a simple directory structure:
  7.  
  8. $ ls
  9. /remote /project /local
  10.  
  11. Assuming a project with a simple structure
  12.  
  13. $ ls project project/code project/settings
  14. project:
  15. code/ settings/
  16.  
  17. project/code:
  18. code.txt morecode.txt
  19.  
  20. project/settings:
  21. settings1.txt settings2.txt
  22.  
  23. 1. #### initialize the repo (optional if only using github)
  24.  
  25. $ cd remote
  26. $ git init --bare
  27. Initialized empty Git repository in remote/
  28.  
  29.  
  30. 2. #### clone the repo locally
  31.  
  32. $ cd local
  33. $ git clone ../remote .
  34. Cloning into '.'...
  35. warning: You appear to have cloned an empty repository.
  36. done.
  37.  
  38. 3. #### copy the project into the local repo
  39. After copying the project, run `git status`
  40.  
  41. $ git status
  42. On branch master
  43.  
  44. No commits yet
  45.  
  46. Untracked files:
  47. (use "git add <file>..." to include in what will be committed)
  48. code/
  49. settings/
  50.  
  51. nothing added to commit but untracked files present (use "git add" to track)
  52.  
  53. Maybe not everything needs to be versioned. To demonstrate that, ignore the `settings` directory.
  54. 4. #### ignore the settings
  55.  
  56. $ echo settings/ > .gitignore
  57. $ git status
  58. On branch master
  59.  
  60. No commits yet
  61.  
  62. Untracked files:
  63. (use "git add <file>..." to include in what will be committed)
  64. .gitignore
  65. code/
  66.  
  67. nothing added to commit but untracked files present (use "git add" to track)
  68.  
  69. 5. #### commit .gitignore and code
  70.  
  71. $ git add .gitignore
  72. $ git commit -m "added gitignore"
  73. [master (root-commit) 8d05149] added gitignore
  74. 1 file changed, 1 insertion(+)
  75. create mode 100644 .gitignore
  76. $ git add code
  77. $ git commit -m "added the code"
  78. [master 13608ef] added the code
  79. 2 files changed, 2 insertions(+)
  80. create mode 100644 code/code.txt
  81. create mode 100644 code/morecode.txt
  82.  
  83. 5. #### push to remote
  84.  
  85. $ git push --set-upstream origin
  86. Enumerating objects: 6, done.
  87. Counting objects: 100% (6/6), done.
  88. Delta compression using up to 4 threads
  89. Compressing objects: 100% (3/3), done.
  90. Writing objects: 100% (5/5), 390 bytes | 390.00 KiB/s, done.
  91. Total 5 (delta 0), reused 0 (delta 0)
  92. To local/../remote
  93. 8d05149..13608ef master -> master
  94. Branch 'master' set up to track remote branch 'master' from 'origin'.
  95.  
  96. Let's assume that they will be using branches
  97. 6. #### create a branch
  98.  
  99. $ git log
  100. commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (HEAD -> master, origin/master)
  101. added the code
  102.  
  103. commit 8d051491c0dd5015fe258430c80568e8158f2b52
  104. added gitignore
  105.  
  106. $ git branch first-branch
  107. $ git checkout first-branch
  108. Switched to branch 'first-branch'
  109.  
  110. $ git log
  111. commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (HEAD -> first-branch, origin/master, master)
  112. added the code
  113.  
  114. commit 8d051491c0dd5015fe258430c80568e8158f2b52
  115. added gitignore
  116. 1. #### commit some changes on the branch
  117.  
  118. $ echo "some more code" >> code/code.txt
  119. $ git status
  120. On branch first-branch
  121. Changes not staged for commit:
  122. (use "git add <file>..." to update what will be committed)
  123. (use "git restore <file>..." to discard changes in working directory)
  124. modified: code/code.txt
  125.  
  126. no changes added to commit (use "git add" and/or "git commit -a")
  127.  
  128. $ git add code/code.txt
  129. $ git status
  130. On branch first-branch
  131. Changes to be committed:
  132. (use "git restore --staged <file>..." to unstage)
  133. modified: code/code.txt
  134.  
  135. $ git commit -m "added more code"
  136. [first-branch 990d3ba] added more code
  137. 1 file changed, 1 insertion(+)
  138.  
  139. $ git log
  140. commit 990d3baac163a5742233ce9a2745ca7fa1e517dc (HEAD -> first-branch)
  141. added more code
  142.  
  143. commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (origin/master, master)
  144. added the code
  145.  
  146. commit 8d051491c0dd5015fe258430c80568e8158f2b52
  147. added gitignore
  148.  
  149. 9. #### change the commit message
  150.  
  151. $ git commit --amend -m "[add] more code"
  152. [first-branch 0675ff3] [add] more code
  153. Date: Sun Oct 13 19:10:34 2019 +0300
  154. 1 file changed, 1 insertion(+)
  155.  
  156. $ git log
  157. commit 0675ff33d03a3f9e662c3fe5ded6e15540802b07 (HEAD -> first-branch)
  158. [add] more code
  159.  
  160. commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (origin/master, master)
  161. added the code
  162.  
  163. commit 8d051491c0dd5015fe258430c80568e8158f2b52
  164. added gitignore
  165.  
  166. 10. #### push the branch
  167.  
  168. $ git push --all
  169. Enumerating objects: 7, done.
  170. Counting objects: 100% (7/7), done.
  171. Delta compression using up to 4 threads
  172. Compressing objects: 100% (3/3), done.
  173. Writing objects: 100% (4/4), 373 bytes | 62.00 KiB/s, done.
  174. Total 4 (delta 0), reused 0 (delta 0)
  175. To C:/Users/Ameteo/Desktop/git stuff/local/../remote
  176. * [new branch] first-branch -> first-branch
  177.  
  178. $ git log
  179. commit 0675ff33d03a3f9e662c3fe5ded6e15540802b07 (HEAD -> first-branch, origin/first-branch)
  180. [add] more code
  181.  
  182. commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (origin/master, master)
  183. added the code
  184.  
  185. commit 8d051491c0dd5015fe258430c80568e8158f2b52
  186. added gitignore
  187.  
  188. 11. #### merge the changes to master
  189.  
  190. Either create a pull request and merge it on github or merge it locally.
  191.  
  192. $ git checkout master
  193. Switched to branch 'master'
  194. Your branch is up to date with 'origin/master'.
  195.  
  196. $ git merge first-branch
  197. Updating 13608ef..0675ff3
  198. Fast-forward
  199. code/code.txt | 1 +
  200. 1 file changed, 1 insertion(+)
  201.  
  202. $ git log
  203. commit 0675ff33d03a3f9e662c3fe5ded6e15540802b07 (HEAD -> master, origin/first-branch, first-branch)
  204. [add] more code
  205.  
  206. commit 13608ef5f5efc7b844e82c46180b2c4c8d1f214b (origin/master)
  207. added the code
  208.  
  209. commit 8d051491c0dd5015fe258430c80568e8158f2b52
  210. added gitignore
  211.  
  212. 12. #### pull the changes (if merged from github) / push the changes (if merged locally)
  213.  
  214.  
  215. $ git pull
  216. Updating 13608ef..0675ff3
  217. Fast-forward
  218. code/code.txt | 1 +
  219. 1 file changed, 1 insertion(+)
  220.  
  221. Or
  222.  
  223. $ git push --all
  224. Total 0 (delta 0), reused 0 (delta 0)
  225. To C:/Users/Ameteo/Desktop/git stuff/local/../remote
  226. 13608ef..0675ff3 master -> master
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement