I have a repository "A" with tons of history, several branches, etc. I want to take a single, clean, working commit and use it as the starting place for a new remote "B", such that there will only be one commit visible on remote "B," and from there I can ideally push to "B" and "A," or even better have that branch of "B" track the origin "A"
-
You might be better off cloning repo A, removing the local `.git` folder, starting a new repo using `git init`, and pushing that to remote B. Using the git tools for this might be cumbersome, especially considering it sounds like you don't want repo A's history. – evolutionxbox May 04 '20 at 19:52
-
`as the starting place for a new remote "B"` - Did you mean `new repository "B"` instead? – customcommander May 04 '20 at 20:01
-
1Does this answer your question? [Make the current commit the only (initial) commit in a Git repository?](https://stackoverflow.com/questions/9683279/make-the-current-commit-the-only-initial-commit-in-a-git-repository) – phd May 04 '20 at 21:02
-
https://stackoverflow.com/search?q=%5Bgit%5D+make+the+current+commit+the+only – phd May 04 '20 at 21:02
2 Answers
Check out the commit where the code is in the state you want it, and create an orphan branch, which will result in a parentless commit when you commit it:
git checkout --orphan clean-branch
git commit -a
git push B clean-branch
Then, checkout the regular branch again and keep working there. Whenever you want to synchronize again, do:
git reset --soft clean-branch
git commit
git push B clean-branch
A soft reset keeps your work directory, but makes it so that the next commits will be on the specified branch.
(I make no statement about whether this workflow is a good idea.)

- 37,289
- 4
- 68
- 81
In general, when you create a new branch off branch “master” you inherit its commit history. The exception is an orphan
(or disconnected) branch. An orphan branch doesn‘t have a parent-child relationship to the master branches’ commits.
Most commits have one parent commit, one obvious exception being root commits which have no parent commits. Creating an orphan branch
will retain the working tree of the branch it’s based on, but without an ancestor commit.
# create new branch b and switch to that: git checkout --orphan b
# create a README.md file: touch README.md;
# add the README.md file to git: git add README.md;
# make first commit to this branch: git commit -m 'orphan branch initial commit';
# push branch b and set upstream branch to branch a: git push --set-upstream a b;
Upstream branches define the branch tracked on the remote repository by your local remote branch (also called the remote tracking branch). To check the tracking branches by writing git branch -vv

- 4,222
- 8
- 24
- 34