Skip to content

Instantly share code, notes, and snippets.

@baconglucose
Last active March 29, 2024 17:09
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baconglucose/079abdcbefa31d0f795d1bf7fd247b0f to your computer and use it in GitHub Desktop.
Save baconglucose/079abdcbefa31d0f795d1bf7fd247b0f to your computer and use it in GitHub Desktop.
How to configure a repository to push to github.

Setting up git

One-time key setup procedures

SSH

Create an SSH key:

ssh-keygen -t rsa -b 4096 -C "Desired comment"
# Give the file a descriptive name.
# Choose a good passphrase.
# Display the (public) key using cat and add it in the GitHub user settings.

Add the key to your ssh agent:

ssh-add "filename.of.private.key"

GPG

Create a gpg key:

gpg --full-generate-key
# Select a default key (RSA and RSA).
# Set keysize to 4096.
# Set the validity to what you want.
# For the real name you can enter the GitHub username.
# For the email address enter the GitHub no-reply-email-address.
# Enter a comment if desired.

Add the key to the GitHub account:

# Display your keys:
gpg --list-secret-keys --keyid-format LONG

# This is the output:
#/Users/hubot/.gnupg/secring.gpg
#------------------------------------
#sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
#uid                          Hubot 
#ssb   4096R/42B317FD4BA89E7A 2016-03-10

# In this case the keyid is 3AA5C34371567BD2, print the key like this:
gpg --armor --export 3AA5C34371567BD2

# Paste the output in the GitHub user settings.

Repository setup procedures

Enter a cloned repository from your GitHub account. If it was cloned using HTTPS, change the remote:

git remote set-url origin git@github.com:username/repositoryname.git
git pull

Set the user and email

Configure the user in the repo:

git config --local user.name "username"

Configure the email in the repo (use the no-reply email):

git config --local user.email "something@users.noreply.github.com"

Set the gpg key and enable signing

Enable automatic signing of your commits:

git config --local commit.gpgSign  true

Finally, set your gpg key used to sign commits:

git config --local user.signingKey 3AA5C34371567BD2
# This is the example keyid from above.
# Display it using `gpg --list-secret-keys --keyid-format LONG`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment