I have been trying to google for a solution but wasnt able to find exactly what I'm looking for, hence the new question.
I have a private git repo with only 1 branch (master) that has ~90 commits.
I want to create a new branch public, that points to another repo - which is public - but not want to show all the commits / history that master have, instead show only 1 commit like "Initial commit".
So far I was able to add a new remote, and set it to track the new branch, but when I push, it sends all the commits that master had.
You first need to create a new branch locally. By default, this will use your current HEAD as a base.
However, you can also create a new branch without any history using git checkout --orphan:
# create a new branch without a history and check it out
git checkout --orphan yournewbranch
# edit your files
# create a commit with these files
git add .
git commit
# push that commit and create the remote branch
git push -u your_remote yournewbranch
Alternatively, you can just create a new repository with that branch and push that:
git init -b yournewbranch
git add .
git commit
git remote add origin https://yourgitserver.com/your/repo
git push -u origin yournewbranch
If you already have the remote branch and want to add it to your repository, you can just checkit out using git checkout:
git checkout -b yournewlocalbranch remotes/yourremote/remotebranchname
This assumes the new branch exists on the remote yourremote with the name remotebranchname and you want the branch to be named yournewlocalbranch
I think what you're trying to do is to squash commits.
Squashing commits essentially lets you simplify your repository by replacing multiple sequential commits with a single one.
How you can do it:
public).git checkout <new_branch>git merge --squash <branch_you_want_squashed>git commit -m "<your_commit_message>"git pushIf you want to learn more about squashing commits you can learn about it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With