How to create a new repository on github

Enable github private Email

  • Github Email Settings

  • Check Keep my email address private and Block command line pushes that expose my email

    Github will remove your public profile email and use 187654321+zyxwv@users.noreply.github.com when performing web-based Git operations (e.g. edits and merges) and sending email on your behalf. If you want command line Git operations to use your private email you must set your email in Git

    Previously authored commits associated with a public email will remain public

Setting your email address for a single repository

git config user.email "187654321+zyxwv@users.noreply.github.com"

Confirm that you have set the email address correctly in Git:

git config user.email

Generating a new SSH key and adding it to the ssh-agent

$ ssh-keygen -t ed25519 -C "187654321+zyxwv@users.noreply.github.com"

Generating public/private ed25519 key pair
Enter file in which to save the key (/home/user-utsrqp/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user-utsrqp/.ssh/id_ed25519
Your public key has been saved in /home/user-utsrqp/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:FFedcbazyxwvu 187654321+zyxwv@users.noreply.github.com
The key's randomart image is:
+--[ED25519 256]--+
..

When you're prompted to "Enter a file in which to save the key", you can press Enter to accept the default file location. Please note that if you created SSH keys previously, ssh-keygen may ask you to rewrite another key, in which case we recommend creating a custom-named SSH key. To do so, type the default file location and replace id_ALGORITHM with your custom key name

You can run ssh-agent automatically when you open bash or Git shell. Copy the following lines and paste them into your ~/.profile or ~/.bashrc file in shell:

env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2=agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi

unset env

If your private key is not stored in one of the default locations (like ~/.ssh/id_rsa), you'll need to tell your SSH authentication agent where to find it. To add your key to ssh-agent, type:

ssh-add /path-to/rsa/github-zyxwv-id_ed25519

海云青飞 注:每天开机启动 bash 环境时,都需要手动输入预先设定的 passphrase

Add host to ~/.ssh/config

Host github-zyxwv
    HostName github.com
    User git
    IdentityFile /path-to/rsa/github-zyxwv-id_ed25519
    Port 22

Adding a new SSH key to your GitHub account

  • Copy the SSH public key to your clipboard

    clip < github-zyxwv-id_ed25519.pub
    
  • github

    • In the upper-right corner of any page on GitHub, click your profile photo, then click Settings
    • In the "Access" section of the sidebar, click SSH and GPG keys
    • Click New SSH key or Add SSH key
    • Title field, add a descriptive label for the new key. For example, if you're using a personal laptop, you might call this key "Personal laptop"
    • Select the type of key, either authentication or signing. For more information about commit signing, see "About commit signature verification"
    • In the Key field, paste your public key
    • Click Add SSH key

Testing your SSH connection

$ ssh -T github-zyxwv

Authenticated to github.com ([140.139.138.137]:22) using "publickey"
Hi zyxwv! You've successfully authenticated, but GitHub does not provide shell access
Transferred: sent 2136, received 2568 bytes, in 1.2 seconds
Bytes per second: sent 1785.5, received 2146.6

Git commands to start a new repository


Get started by creating a new file or uploading an existing file. We recommend every repository include a README, LICENSE, and .gitignore

# Create a new repository on the command line
echo "# The best repository in the world" >> README.md
git init
git config user.email "187654321+zyxwv@users.noreply.github.com"
# git remote add origin https://github.com/zyxwv/sro.git
git remote set-url origin git@github-zyxwv:zyxwv/sro.git
git branch -M main
git add README.md
git add .gitignore
git commit -m "first commit"
# git push -u origin main
git push --set-upstream origin main

In the command git push -u origin main, the -u option stands for --set-upstream. This option is used to set the upstream tracking reference for the branch you are pushing, which allows you to use simpler commands in the future, like just git push or git pull without specifying the remote and branch name again.

By using -u, you establish a connection between your local branch and the specified remote branch, making it easier to synchronize changes between them in subsequent operations.

Referebces:

2024-11-09


独立思考最难得,赞赏支持是美德!(微信扫描下图)