Intro
One of the easiest way to connect your Github account with your git installed on Mac or Windows is through Github Desktop. But, we can’t use that on wsl, so we use PAT(personal access token) to resolve this issue!
Steps to setup on Windows 11
- install git on Windows
- install Github Desktop
- Login your Github Desktop with your Github account
install git on Mac/WSL 2/ Linux
- Install git(if not already installed)
- Mac:
brew install git
- Linux/WSL2(debian):
sudo apt-get install git
- Mac:
- check git version with
|
|
- setup git global config
|
|
install Github CLI
-
download and install Github CLI following this tutorial. In Ubuntu, you can install it with apt.
-
login in the Github website
|
|
- test: clone, commit and try to push a github repo
|
|
- output example:
|
|
Sign your commit with GPG key
-
Generate a GPG Key:
Open a terminal and generate a new GPG key pair:
1
gpg --full-generate-key
Follow the prompts to create your key. Choose the following options when prompted:
- Select kind of key:
(1) RSA and RSA (default)
- Key size:
4096
- Key expiration:
0
(never expires)
- Select kind of key:
-
List Your GPG Keys:
After generating your key, you can list your keys to get the key ID:
1
gpg --list-secret-keys --keyid-format LONG
Look for the
sec
section and you can get thelong key ID
at the second line. -
Copy Your GPG Key:
Use the
long key ID
to copy your GPG key:1
gpg --armor --export <your-long-key-id> > my-gpg-key.asc
-
add GPG key to Github account
Use the File Path with GitHub CLI:
Now, you can use the file path with GitHub CLI:
1
gh gpg-key add my-gpg-key.asc
Yes, you can use GitHub CLI (gh) to simplify the process of adding your GPG key to GitHub. Here are the steps to do so:
-
Configure Git to Sign Your Commits:
Configure Git to use your GPG key for signing commits:
1 2
git config --global user.signingkey <your-long-key-id> git config --global commit.gpgSign true
-
Make and Sign a Commit:
Make a new commit and push it to GitHub. The commit should be signed automatically if you enabled commit signing by default:
1 2
git commit -m "Your commit message" git push
To manually sign a commit, use the
-S
flag:1
git commit -S -m "Your commit message"
These steps leverage GitHub CLI to streamline the process of adding your GPG key to GitHub and configuring Git to sign your commits.