Cloning GitHub Repositories: Modifying Code Without Pushing Changes
Maya Ifrim

Maya Ifrim

Apr 26, 2023

Cloning GitHub Repositories: Modifying Code Without Pushing Changes

I recently tried to clone one of my GitHub repositories onto my local machine to make some changes and test them out, without pushing the changes back to the original repository. However, I realised the can't fork my own repositories which was a bit frustrating. After searching the internet for ways to clone a GitHub repository without pushing changes back to the original, I attempted several approaches, none of which seemed to work. I felt lost and frustrated, unable to find a solution to my problem.

Fortunately, I eventually found a post on StackOverflow that provided two solutions. The first solution involved cloning the repository, pushing it to a new repository, and setting a new URL origin. Here are the steps:

image.png

The second solution was to use GitHub importer, but I chose the first option because it was good enough for my needs.

Deleting commit history in a Git repository is generally discouraged because commits represent the project's history and the changes made to it. However, in cases involving sensitive information, it may be necessary to delete commits. This was my case, and with same simple steps I managed to do it very quickly.

1. Create a new orphan branch in the Git repository. This branch won't be listed in the git branch command.

$ git checkout --orphan temp_branch

2. Add all files to the newly created branch and commit them using the following commands.

$ git add -A

$ git commit -am "Initial commit"

3. Delete the master or main branch from your Git repository.

$ git branch -D main

4. Rename the newly created branch main.

$ git branch -m main

5. Forcefully push the changes to the remote repository.

$ git push -f origin main

Maya Ifrim

Maya Ifrim

Passionate React developer with a love for crafting beautiful and user-friendly interfaces.

Leave a comment

Related Posts

Categories