BlockLune's Blog

Home Tags About

Simple GitHub Tutorial

I have posted a tutorial of Git (See Simple Git Tutorial). But it mixed up using Git and using GitHub together. I post this new tutorial to draw a line and make things clear.

Notice: If you run into any problems, it’s highly recommended that you check out Github Docs, or Google it. If you still can’t solve it, you can comment below this post.

Creating a Github Account

See:

Checking your Local Git Config

Make sure that you have told Git your name and email. That is say, you should have run:

git config --global user.name "<your_name>"
git config --global user.email "<[email protected]>"

Also see:

Connecting to GitHub with SSH

You are recommended to connecting to GitHub with SSH (instead of HTTP/HTTPS).

First, generate a new SSH key using new ED25519 algorithm:

ssh-keygen -t ed25519 -C "<[email protected]>"

Then, Keep on repeating pressing Enter until your prompt appear again.

Finally, add your public key to GitHub:

  1. Go to SSH and GPG keys - GitHub.
  2. Click the green New SSH key button at the top right of the page.
  3. Fill out the form, where key is the content of ~/.ssh/id_ed25519.pub (This file is generated by the ssh-keygen command above. You may run cat ~/.ssh/id_ed25519.pub on Linux or Mac or run notepad ~/.ssh/id_ed25519.pub on Windows to check its content).
  4. Submit the form by clicking the green Add SSH key button.

The postfix .pub indicates that the id_ed25519.pub file is a public key. The ssh-keygen command above also generates a private key file id_ed25519 (without the .pub postfix).

Also see:

Due to the special network environment in China, you may often need to use proxy service to get a better browsing experience. Generally, when you enable the System Proxy option, only the traffic on port 80/443 (corresponding to HTTP/HTTPS) will go through the proxy server, while the traffic on SSH’s default port 22 will not. With the following settings, you can force SSH traffic to go to port 443.

To test if SSH over the HTTPS port is possible, run:

ssh -T -p 443 [email protected]

Type yes if you see some info like:

Are you sure you want to continue connecting (yes/no/[fingerprint])?

If you receive response like below, it means it’s OK:

Hi USERNAME! You've successfully authenticated, but GitHub does not
provide shell access.

You can now override your SSH settings to force any connection to GitHub.com to run through that server and port. Edit ~/.ssh/config and add this section:

Host github.com
    Hostname ssh.github.com
    Port 443
    User git

Now your usual command like:

git clone [email protected]/YOUR-USERNAME/YOUR-REPOSITORY.git

is equivalent to:

git clone ssh://[email protected]:443/YOUR-USERNAME/YOUR-REPOSITORY.git

Also see:

GitHub Cli

TODO

Basic Usages

Cloning

You can use git clone to clone an existing repo from GitHub. The simplest form looks like:

git clone <url> [<local_directory_name>]

where center brackets mean that <local_directory_name> is optional.

It’s no longer recommended to use http/https url to clone. Using url like [email protected]:YOUR-NAME/YOUR-REPOSITORY.git!

If you want to specify a branch when cloning, you can use -b option:

git clone -b <branch> <url>

If you don’t want to include all commits, you can use the --depth option. This is helpful when cloning a large repo (you don’t need so many commits before actually).

git clone <url> --depth=1

Next Steps

TODO

Resources