Before I had a basic understanding of how git works, I used to keep my local repo all the time, even after I had pushed changes to the remote repo in GitHub. However, I now realize that if I am done working on something for a while, I can remove the local repo and simply clone/copy from my GitHub repository when I’m ready to work on it again. This prevents working on an old copy of files in a local repo that you’ve left around. Cloning a repo is pretty simple, here is what it looks like.
First, go to the remote repo wherever it stored, in my case, GitHub. Click the Clone or download button, then the clipboard icon to copy the URL to your clipboard.
Next, go to your favorite console that has git commands available, in my case, we’ll be working in PowerShell. Navigate to the top-level folder where you want to store the project files, and use the git clone command along with the previously copied URL.
After git has copied the files down from the remote repo, you can see a new folder created with the name of the repo (in this case, RandomFileGenerator-Module):
Changing directories into our new folder will show the same files have been copied locally that were available in the remote repo:
Even though the local repo is brand new to the system right now, it has the same history available as the remote repo. If you run git log, you can see the previous commits made. The orange arrow here is showing where I merged the master branch of the remote repo with a previous local repo (see my previous blog on this):
And that’s it! Now you can work on this local copy, commit your changes, upload back to the remote repo, then delete the local files.