课程: Coding Exercises: GitHub

Clone a repo with an empty history - GitHub教程

课程: Coding Exercises: GitHub

Clone a repo with an empty history

(electronic sounds) - [Instructor] Let's begin with something that might be a bit handy for this course. How do you make a copy of an existing repo without copying any of its history, even if the repo is not yours? I'll give you a couple of seconds to pause the video and see how you would have solved it. (electronic sounds) All right, there's a few ways that we can do this. The tough part is that I want a clean history. That's not associated with the original repo. Now you could forge the repo, but you can only do that once. And then you'd still have a link to the original. Another way is to create a template repository, but you can only do that if you're the owner of the repository. But there's a much faster and flexible way. You can use a project called Degit by Rich Harris, the maker of this Vout framework. Degit lets you do exactly what we're looking for. We'll also need to use npx, which comes when you install NodeJS, the command looks like this. Now npx will allow you to temporarily use a project without having to download it so we can run the Degit project. From there, you can specify a GitHub username, although it defaults to GitHub. It will also work with other products like Bitbucket and GitLab by adding it as a prefix with a semi-colon. In addition to the username, you can specify a project's name. You can even choose to only copy an existing branch release or hash by adding that after a hashtag symbol, then finally you specify what you want to call the project locally, separating the name with a space. Let's try this command. I'm going to switch over to hyper, which is my terminal. I'm going to make sure that I switched to the desktop and then also issue the npx Degit command. And I'm going to target the LinkedIn learning group and then type in the name of the repository I want the copy. And then I'm going to enter the name that I want to call this locally. I'm going to hit enter. And I'm going to say yes right here. Now this is going to clone the repository to my desktop. Since this is a brand new repo, you'll still need to initialize git, create a repo and then push this to GitHub. But it's the fastest way to get started with a clean history. I'm going to be using something like this to copy clean GitHub projects. When I show you some of the other challenges.

内容