Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git branch without history

Tags:

git

branch

My git repo contains sensitive passwords which, for reasons out of my control, can't be removed right now. Right now it's all OK because this repo is internal-only, but I've been asked to create a branch that's safe to share with partners.

Is there any way to create a branch in git and then remove files from it in a way where they can't be retrieved using the log?

Seems like a long shot, but thought I'd ask. The only solution I can think of is to copy the file tree to a new git repo without the sensitive file--but then I'd lose the ability to merge partner changes back to my repo.

like image 657
Ben K. Avatar asked Aug 27 '09 20:08

Ben K.


People also ask

How do you commit without history?

Create a new orphan branch, named <new_branch>, started from <start_point> and switch to it. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.

What is orphan branch in git?

An orphan branch, not surprisingly, has no parents (meaning, git history) when it is created. The history of the orphan branch is separate from other branches in the repository, including the main or root branch it was created from.

How do I create an empty branch in an existing repository?

As of Git 2.23, you can use git switch --orphan <new branch> to create an empty branch with no history. Unlike git checkout --orphan , all tracked files will be removed.

How do I create an empty branch in github UI?

To create empty branch, you have to go to terminal and execute: git checkout --orphan branchname git rm -rf . Only after that you may see the new branch on GUI. Please, add the feature for creating new empty (without parent) branches on GUI.


1 Answers

One thing you could do is create a branch of your repo, edit out the passwords, and then create a shallow clone (with depth 1) of that repository that you would give to the partners. They can make patches and whatnot against that clone, but can't see the whole history and can't push the repo anywhere else. If they're just making changes, then this should be a workable solution. You can still accept patches from them and apply to your master repository.

See the --depth option of git clone for further information.

like image 138
Greg Hewgill Avatar answered Oct 11 '22 09:10

Greg Hewgill