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?#
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.
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.
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.
If prompted "No such file or directory", it means that an ssh key has not been generated on this machine. Execute the following command
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:
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+.
Go back to your GitHub user page, click the top right corner, go to settings, and click SSH and GPG keys on the left.
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.
After completion, use the following command in the terminal to confirm whether the SSH key is successful
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:
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.
To synchronize the cloud code to your local machine, use the command:
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.