Advertisement
Guest User

Untitled

a guest
May 27th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. # How to use Git ?
  2.  
  3. ## Set up your fork
  4.  
  5. 1. Go to the origin repository page at [https://github.com/Flash2307/ProjetS6](https://github.com/Flash2307/ProjetS6).
  6.  
  7. 2. Click on the "Fork" button at the top right of the page
  8. ![Fork button](http://s33.postimg.org/tq66ip5fz/Sans_titre.png)
  9.  
  10. 3. Once your fork is ready, you need to clone it. Use the green "Clone or download" button to retrieve the repository's URL.
  11. ![Clone button](http://s33.postimg.org/a5g5zkde7/Sans_titre.png)
  12.  
  13. 4. Now that you have your repository's URL, you are ready to clone it. You can either use Git CLI (command-line) or use a GUI software such as (TortoiseGit, SourceTree, GitKraken, etc.).
  14.  
  15. If you are using the CLI, run :
  16.  
  17. ```
  18. git clone {YOUR FORK'S URL}
  19. ```
  20.  
  21. **You may need to enter your github credentials.**
  22.  
  23. 5. As your fork as a completely separate repository from the origin, you will need to periodicly sync your fork with it. To do so, you need to add a "remote" repository to your fork.
  24.  
  25. If you are using the CLI, run the below command from within your new cloned repository :
  26.  
  27. ```
  28. git remote add upstream https://github.com/Flash2307/ProjetS6
  29. git fetch upstream
  30. ```
  31.  
  32. From now on, once you want to "pull" the latest changes from the origin, you should run :
  33.  
  34. ```
  35. git pull upstream master
  36. ```
  37.  
  38. You should run the above command at least every time you are about to push something.
  39.  
  40. ## Quick steps to "push" your changes to your remote fork
  41.  
  42. If you made changes into your fork, you will surely want at some point to include within the origin repository.
  43.  
  44. 1. Pull the changes from the origin :
  45.  
  46. ```
  47. git pull upstream master
  48. ```
  49.  
  50. 2. Choose the files you want to send to the origin.
  51.  
  52. ```
  53. git status #Will show all the files that changed since the last revision
  54. git diff --color #Will show all the changes in each file since the last revision
  55. git diff --color --staged #Will show all the changes in each file since the last revision ready to be committed
  56. git add <path/to/file> #Will make the specified file ready to be committed (file will be staged)
  57. git add -a #Will make all files ready to be committed
  58. ```
  59.  
  60. 3. Once you have selected which files you want to commit, you obviously need to commit them.
  61.  
  62. ```
  63. git commit -m '{some description of your work}'
  64. ```
  65.  
  66. 4. The previous step, create a **local** revision of your changes. You now need to push that revision into your **remote** fork. This is call a "push".
  67.  
  68. ```
  69. git push {remote_branch} #If you are working without branches, then your {remote_branch} is master
  70. ```
  71.  
  72. ## Quick steps to "merge" your changes from your remote fork to the origin
  73.  
  74. The previous steps brought your local changes to your remote fork. We will now see how to incorporate them into the origin.
  75.  
  76. 1. Go to your remote fork home page [https://github.com/{your_username}/ProjetS6](https://github.com/{yourUsername}/ProjetS6).
  77.  
  78. 2. Click on the "New Pull Request" button.
  79. ![New Pull Request button](http://s33.postimg.org/xvaqwg72n/Sans_titre.png)
  80.  
  81. 3. Select the remote branch from your fork that you want to merge with the origin and make sure that the origin's branch is "master". You can also revised your changes before you hit the "Create pull request button".
  82. ![Pull Request steps](http://s33.postimg.org/9wyciz1zj/Sans_titre.png)
  83.  
  84. 4. Wait for someone to approve your pull request. Once that's done, your changes will be merged.
  85.  
  86. **YOU SHOULD NEVER MERGED YOUR OWN PULL REQUESTS.**
  87.  
  88. ## Use branches
  89.  
  90. By default, you are always inside the "master" branch. Creating a branch helps you to separate your work especially if you are working on several things at the same time. For example, if you are in branch "branchA" and you make changes, the "master" branch won't know about it unless you merged the two branches. We call that separation of duties.
  91.  
  92. ### Create a branch
  93.  
  94. git branch branchA
  95.  
  96. ### Change branch
  97.  
  98. Before you do so, you need to make sure that the branch you want to switch to exist. Also, if you made any changes in the branch you are currently in, you need to commit them before changing branch.
  99.  
  100. git checkout branchA
  101.  
  102. ### Delete local branch
  103.  
  104. git branch branchA -d
  105.  
  106. **You can't delete the branch that you are currently in. To do that, you first need to switch to another branch (master for example).**
  107.  
  108. ### Delete remote branch
  109.  
  110. git push origin :branchA
  111.  
  112. If your repository was tracking a remote branch and someone deleted it, you can resync your repository with :
  113.  
  114. git fetch -p
  115.  
  116. You will no longer be tracking the deleted remote branch.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement