Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Setting up a git repo
- =====================
- 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.
- 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.
- First before the git can be created an SSH key must be created if you want to push repo into you GitHub account.
- ## SSH Key
- * First you have to generate a new SSH Key. Use the following command:
- ```bash
- ssh-keygen -f ~/.ssh/$SSH_KEY_NAME
- ```
- * Go to config file (`~/.ssh/config`), if there isn't one create one named 'config'.
- * Now add in the file the following:
- ```
- Host $REPO_NAME
- Hostname github.com
- IdentityFile ~/.ssh/$SSH_KEY_NAME
- User git
- ```
- * `$REPO_NAME` should be a simplified name for the repo, as well as the `$SSH_KEY_NAME` will be.
- * Now run the following command to get your public key:
- ```bash
- cat ~/.ssh/$SSH_KEY_NAME.pub
- ```
- * 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.
- ## GPG Key (optional)
- 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.
- 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.
- This adds an extra layer of security, especially needed when creating code which will be commited to 'important' code, like git itself.
- 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:
- ```bash
- gpg --generate-key
- ```
- Now simply follow the steps they ask you.
- ## Git Repo
- Once you have created the repo by running `git init` and added some code to the directory, do the following:
- <br />
- **\<OPTIONAL>**
- * This step is if you want to sign all your commits with you key pair:
- ```bash
- git config --global user.signingkey $YOUR_KEY_ID
- ```
- `$YOUR_KEY_ID` should be the unique ID your private key has. To find this ID, run:
- ```bash
- gpg --list-secret-keys --keyid-format LONG
- ```
- **\</OPTIONAL>**
- <br />
- * Add all the file to the stage:
- ```bash
- git add .
- ```
- * Now commit all changes with message "first commit":
- ```bash
- git commit -m "first commit"
- ```
- * 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:
- ```bash
- git remote add origin $REPO_NAME:$YOUR_GITHUB_USERNAME/$NAME_OF_GITHUB_REPO
- git remote set-url origin $REPO_NAME:$YOUR_GITHUB_USERNAME/$NAME_OF_GITHUB_REPO
- ```
- `$NAME_OF_GITHUB_REPO` should be named _exactly_ like the repo you created in your GitHub account, otherwise you might run into some trouble.
- * Now pull the code first (it's always good practice to this first)
- ```bash
- git pull
- ```
- * Now push* code
- ```bash
- git push -f --set-upstream origin master
- ```
- Everything should be fine now. Happy coding :)
- *_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