On New Year’s Day, I set up a website called “The Path to Java Programmer Advancement”, which uses Git as a synchronization tool between the cloud server and GitHub remote repository.
As a developer, we all know the importance of Git. Git is a distributed version control software, originally developed by Linus Torvalds and released under the GPL license in 2005.
I will not brag about Git this time. After all, I have brag about Git for 7 times.
- Probably the greatest code commit in Git history
- Finally, someone has spelled out Git’s data model
- I lost sleep last night after Linus submitted his first Git code!
- To be proficient with Git, you probably need to remember these 60 commands
- Crash! Interns made a mess of the team’s code repository…
- Believe it or not, just 7 pictures will give you a pretty good handle on Git branch management.
- Douban 9.1 points! I finished this book in the emergency room yesterday!
Git alone can make anyone a god, and Linus is the developer of the Linux kernel, which is the highest level of god.
Git spring-checkout (Git spring-checkout) : Git spring-checkout (Git spring-checkout) : Git spring-checkout (Git spring-checkout)
A big problem with using Git
First of all, let me tell you that the website “The Path to Java Programmer Advancement”, which was launched a day ago, has been visited more than 1000 times.
Is the so-called short step without thousands of miles, not small streams into rivers and seas.
1000 times may not be worth mentioning, but 10 million is still only 11 thousand thousand, the second brother made every little progress, thanks to everyone’s support.
I clone a remote repository on GitHub on the cloud server, execute git pull command to pull the latest content from GitHub through the scheduled task on the pagoda panel, and then build the website through the Nginx server. The site content is derived from a Docsify render MD file.
Direct Git pull will mindtlessly synchronize the Codes and images directories on GitHub to the cloud server, but actually there is no need to synchronize the codes and images directories.
What’s going on?
You can take a look at my GitHub repository directory structure.
- Docs is the documentation directory, which contains the MD file, where all the tutorial manuscripts are located.
- Codes are code directories that contain the source code for tutorials.
- Images is an image catalog that contains hand-drawn illustrations to accompany the tutorial.
This way, you can use GitHub to make free map beds, and also get free jsDelivr CDN global acceleration.
For example, there is a logo in the images directory.
If you use the original path of GitHub repository to access, the speed is slow!
Github.com/itwanger/to…
Speed up with jsDelivr is different. Speed up!
Cdn.jsdelivr.net/gh/itwanger…
GitHub can be used as a map bed in two ways:
- Create a GitHub repository as a bed repository and upload and submit images to the repository
- Change the link to where you want to use the GitHub bed image
https://cdn.jsdelivr.net/gh/ {user} / {'} / image path
Pay seven niuyun or Ali yuntu bed partners might as well try this way, can free ticket ZA never spend a minute of money.
That said, the images on the Java Programmer’s Path are loaded from the GitHub map bed, rather than being pulled from the GitHub repository to the cloud. You know, a cloud server space is extremely expensive, can save space we have to save.
A big surprise in learning Git
So I was wondering this morning, how can I save this expensive space?
I baidu a lot of posts, the vast majority of them are messy, worthless, very few of them are to the point.
Finally, it took a look at the Git manual (or Pro Git) to find a cool command: Git sparse-checkout, which allows you to sync only the directories and files you want when pulling remote repositories.
For details, please refer to the official document:
Git-scm.com/docs/git-sp…
But there’s no need, HHHH. Let’s just do it.
The first step, through the git remote add -f orgin [email protected]: itwanger/toBeBetterJavaer git command on the pull out the warehouse.
Second, enable Sparse-checkout and initialize
After pulling to the repository, run git config core.sparseCheckout true to enable sparse-checkout.
Git sparse-checkout init initialization is then performed.
Third, use sparse-checkout to pull the desired warehouse catalog
For example, if we only wanted to pull the docs directory, we could run git sparse-checkout set docs.
If you’re using sparse-checkout for the first time, you’ll need to execute git pull orgin master once more.
The fourth step is to verify whether it takes effect
Check for sparse-checkout by executing the ls-al command.
As you can see, only the docs directory is actually pulled.
If you want to pull other files or directories, you can do so with the git sparse-checkout add command.
This enables custom synchronization between the remote repository and the cloud server repository, synchronizing whatever directories and files you need, and eliminating anything you don’t.
GitHub repositories are free to use and have unlimited space, but cloud services can be very expensive.
By comparison, the remote warehouse is about 145 M, and the images take up 72 M, no problem saving half of the storage space.
How to disable Git sparse-checkout?
It’s as simple as executing git sparse-checkout disable.
As you can see, all those unwanted directories and files are coming back.
What if it’s enabled again?
It’s as simple as executing git sparse-checkout reapply.
To summarize: If you’re pulling a remote repository that’s big enough to fill your hard drive, and you only need a few directories and files, try Git sparse-checkout.
A little truth after using Git
Git is pretty powerful, I have to say. With a single command, my cloud server with 80 gigabytes of storage can fight for another 3 years and never worry about it again.
Git is really awesome, Linus is really awesome, god is god!
Hello everyone, I am the second brother with liver pain on the weekend!
Yesterday’s article issued after, good friend G elder brother message said: “elder brother also don’t go out happy next?” The implication is that the second brother is too liver, even the weekend did not let go, it is too heartless.
The main reason is that I finally have a consistent period of time and I have a lot of things I want to do. For example, I changed the style of video recording this time, tried to add BGM, and tried to find a lot of materials to enrich the video picture.
Computer science students can take a look at the following links to see how this winter vacation should be solved. If you think the video is helpful, you might as well with the support of sanlian, let the second brother’s B station in 2022 can be a little better. The so-called spark, it is up to you to light.
Video address: www.bilibili.com/video/BV1vq…
Tomorrow is another working day in 2022, and I hope everyone in the Working Party can make further progress!
Nothing keeps me here but purpose, and though there are roses by the shore, and trees by the shore, and still harbours, I am not tied.