Git

How to Copy a Git Repo Without History?

On GitHub, developers work on different remote repositories. Sometimes, they want to make their private repositories public or copy the remote repository to the local repository. However, some repositories’ commits contain secret information they do not want to make visible publicly. So, Git allows them to copy or publicize the remote repository without history.

This write-up will explain the process of copying a Git repository without history.

How to Clone Particular Git Repository History?

To copy a Git local repository without log history, follow the below-listed steps:

  • Navigate to the local directory.
  • Choose a particular GitHub Repo and copy its HTTP URL.
  • Clone Git Repo without history using the “git clone –depth 1 <remote-URL>” command.
  • View commit history.

Step 1: Switch to Particular Local Repository

First, type out the “cd” command along with the desired path and redirect to it:

$ cd "C:\Git\test_3"

Step 2: Copy Remote URL

Then, open GitHub, navigate to the required remote repository that you want to clone, and copy its “HTTP URL” to the clipboard:

Step 3: Clone Remote Repository

Now, use the “git clone” command along with the desired depth and HTTP URL of the remote repository to copy that particular repository:

$ git clone --depth 1 https://github.com/laibayounas/newRepo.git

Here, the “–depth” option is used to get the desired amount of commits. The “depth 1” will include the latest commit only:

Step 4: Navigate to Remote Repository

Next, redirect to the cloned Git repository using the “cd” command:

$ cd newRepo

Step 5: Check Reflog

Lastly, view the commit history by checking the reference log:

$ git reflog .

The below-screenshot displays the latest commit only, which means the Git repository has been copied successfully without history:

We have demonstrated the easiest method of copying a Git repository to a local repository without history.

Conclusion

In order to copy the Git repository without history, first, switch to the local repository. Then, open GitHub, go to a particular GitHub remote repository, and copy its URL. After that, copy the remote repository to the local repository by executing the “git clone –depth 1 <remote-URL>” command. Lastly, view the Git repository reference log to verify the changes. This write-up explained the process of copying a Git repository without history.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.