KANIKIG

KANIKIG

just for fun | 兴趣使然 Ph.D. in Engineering|❤️ #NFT $ETH| [Twitter](https://twitter.com/kanikig2)|[Github](https://github.com/KANIKIG)|[Telegram channel](https://t.me/kanikigtech)

Start your GitHub journey

image

Introduction#

Suitable for systems: Linux and MacOS

Reading this article requires some knowledge of Linux and a little understanding of Linux commands.

What is GitHub?#

git.png

github.jpg

To understand what GitHub is, you first need to understand what Git is:

Git (pronounced /gɪt/) is an open-source distributed version control system that can efficiently and quickly handle version management of projects ranging from small to very large. The biggest difference compared to centralized systems is that developers can commit to their local machines, and each developer can clone (git clone) a complete Git repository on their local machine.

GitHub:

GitHub is a hosting platform for open-source and private software projects. It is named GitHub because it only supports git as the only version control format for hosting.

In simple terms, it allows you to upload the code projects you write on any device at any time, and you can download them on any device to achieve multi-device synchronization.

Main Content#

Create your own git project repository#

After registering on GitHub, go to your personal account page and click the New button to create a Repository.

img20431.png

You can name it as you like, preferably similar to your local project folder, which will be used later. For example, I created the content of my own R language learning here.

Local deployment of git#

Installation is very simple, just need to know some commands.

$ sudo apt install git-all # for Debian-based systems

$ git --version # for MacOS, run this command after installing Xcode Command Line Tools. The installation of Xcode Command Line Tools is also very simple, please find it yourself.

For installation on other systems, please refer to the git official website: Getting Started with Git

Associate your machine with GitHub#

I believe friends who have played with servers should know what ssh is. Since git completes file upload and download through ssh, you need to fill in an ssh key file to GitHub to authenticate your machine.

$ cd .ssh 

If prompted "No such file or directory", it means that an ssh key has not been generated on this machine. Execute the following command

$ ssh-keygen -t rsa -C "your email address"

When this step is completed, a rectangular ASCII art will appear, indicating that the generated ssh key has been saved in the .ssh folder.

Then open the key file and copy all its contents:

$ cat ~/.ssh/id_rsa.pub
# or if you know how to use vim
$ vim ~/.ssh/id_rsa.pub

Of course, you can also open it directly with a text editor. The .ssh hidden folder is located in your user folder. On MacOS, the shortcut to show hidden files is Ctrl+Shift+.

img20433.png

Go back to your GitHub user page, click the top right corner, go to settings, and click SSH and GPG keys on the left.

20434.png

20435.png

Click "New SSH key" in the top right corner, give it a title, and paste the contents of the copied key file into the box below to save it. This completes the GitHub authentication.

20436.png

After completion, use the following command in the terminal to confirm whether the SSH key is successful

$ ssh -T [email protected]

# If the following content appears at the end, it means success
Hi your_username! You've successfully authenticated, but GitHub does not provide shell access.

Configure and upload the project folder to git#

In the terminal, use cd to enter the project folder you want to synchronize, and run the following commands:

$ git init # initialize, after running this step, your terminal will display git:(master) ✗ 

$ git add . # the official guide says to add README.md, but that's just an example, it only uploads the README.md file. The significance here is to synchronize all the contents of this folder

$ git commit -m "first commit" # the content in quotes is the reason for your upload update

$ git branch -M main

$ git remote add origin https://github.com/your_username/your_repository_name.git 
# If you forget the repository name, go to your repository page in the browser, copy the URL and add .git at the end

$ git push -u origin main # push to upload

Done! Now go back to the repository page, and you will see that the contents of the folder are already there!

In the future, just use cd to enter the project folder and execute the following commands to upload updates.

$ git add .
$ git commit -m "reason for update"
git push -u origin main

To synchronize the cloud code to your local machine, use the command:

$ git pull --rebase origin master

Now you can happily upload all your projects to GitHub!

Some content in this article refers to the article by 3y: https://github.com/ZhongFuCheng3y/3y with some modifications and improvements.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.