Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. Setting up a git repo
  2. =====================
  3. When first setting up a repo, it's important to remember what commands to remember and what the default settings should be, this is what this file is for.
  4. This file will not include _all_ settings that need to be set up but rather the bare minimum that are common. It will also include how to work with GitHub. All this is designed for a Linux Desktop.
  5. First before the git can be created an SSH key must be created if you want to push repo into you GitHub account.
  6.  
  7. ## SSH Key
  8. * First you have to generate a new SSH Key. Use the following command:
  9. ```bash
  10. ssh-keygen -f ~/.ssh/$SSH_KEY_NAME
  11. ```
  12. * Go to config file (`~/.ssh/config`), if there isn't one create one named 'config'.
  13. * Now add in the file the following:
  14. ```
  15. Host $REPO_NAME
  16. Hostname github.com
  17. IdentityFile ~/.ssh/$SSH_KEY_NAME
  18. User git
  19. ```
  20. * `$REPO_NAME` should be a simplified name for the repo, as well as the `$SSH_KEY_NAME` will be.
  21. * Now run the following command to get your public key:
  22. ```bash
  23. cat ~/.ssh/$SSH_KEY_NAME.pub
  24. ```
  25. * Go to your GitHub repo settings and then add all of the text to your 'Deploy keys' tab, make sure key has writing access rights.
  26.  
  27. ## GPG Key (optional)
  28. Sometimes, when writing code it can be useful to make sure people, when looking at your code, can be sure that the changes were made by you and you alone.
  29. Key pairs are used to sign new code changes. The private key is used for the signature, while the public is used to certify the changes were from you.
  30. This adds an extra layer of security, especially needed when creating code which will be commited to 'important' code, like git itself.
  31. However, this may not be needed if it is you who is the only one commiting to your repos. To create a new Private and Public key run the following:
  32. ```bash
  33. gpg --generate-key
  34. ```
  35. Now simply follow the steps they ask you.
  36.  
  37. ## Git Repo
  38. Once you have created the repo by running `git init` and added some code to the directory, do the following:
  39. <br />
  40. **\<OPTIONAL>**
  41. * This step is if you want to sign all your commits with you key pair:
  42. ```bash
  43. git config --global user.signingkey $YOUR_KEY_ID
  44. ```
  45. `$YOUR_KEY_ID` should be the unique ID your private key has. To find this ID, run:
  46. ```bash
  47. gpg --list-secret-keys --keyid-format LONG
  48. ```
  49. **\</OPTIONAL>**
  50. <br />
  51.  
  52. * Add all the file to the stage:
  53. ```bash
  54. git add .
  55. ```
  56. * Now commit all changes with message "first commit":
  57. ```bash
  58. git commit -m "first commit"
  59. ```
  60. * Then you have to 'connect' the SSH key to your git repo and make sure it pushes to the right GitHub account and GitHub repo. Run both lines:
  61. ```bash
  62. git remote add origin $REPO_NAME:$YOUR_GITHUB_USERNAME/$NAME_OF_GITHUB_REPO
  63. git remote set-url origin $REPO_NAME:$YOUR_GITHUB_USERNAME/$NAME_OF_GITHUB_REPO
  64. ```
  65. `$NAME_OF_GITHUB_REPO` should be named _exactly_ like the repo you created in your GitHub account, otherwise you might run into some trouble.
  66. * Now pull the code first (it's always good practice to this first)
  67. ```bash
  68. git pull
  69. ```
  70. * Now push* code
  71. ```bash
  72. git push -f --set-upstream origin master
  73. ```
  74.  
  75. Everything should be fine now. Happy coding :)
  76.  
  77. *_I highly recommend to _never_ add the `-f` argument into git unless you are the sole contributor. As it can wreak havoc with code or accidental deletion, be careful_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement