Reputation: 1392
I'd like to push my project and share the repo on Github and my coworkers. But I have one problem, while I'm developing the project I committed some private stuff e.g. passwords to the git, so I don't want to commit the history to Github. I just need to share the latest version of the Project, one last commit to Github, without past commits, history.
What I tried:
git push -u github_tmp d3710442f80889be21324d5be14a25fe4a0d0274:refs/heads/main
This didn't work, this does commit to Github but it shows me not 1 commit but like 26 commits (yes included all the past commits history on the branch)
So, how can I do that? Thanks.
Upvotes: 2
Views: 3397
Reputation: 541
The best approach is git rebase
. You can delete the commits that you do not want to be pushed.
You can also "squash" together any commits that you want to be seen as single commit.
If you want to keep the commits locally then you create a new branch to be pushed.
git switch -c my-branch-to-push
git rebase -i oldest-commit-to-start my-branch-to-push
Now you get to edit the list of commits, and you can remove entries from it.
Then you git push
the new branch. (might have to set upstream tracking)
Of course, if your current branch already has the upstream set, then you keep the newly created branch, and rebase the current.
You can also do
git filter-branch
https://git-scm.com/docs/git-filter-branch But it has its pitfalls....
Upvotes: 1
Reputation: 91
If you don't need your history in local you can reset to the origin branch using the mixed reset,
git reset --mixed origin/<branch>
with mixed reset you lost your history, but not your changes, nothig happens to your working directory
more info about reset https://git-scm.com/docs/git-reset
a this point you don't have nothing to push and you can commit in a new commit
Upvotes: 0