Post B2cBo6PLt9SsChARsW by pmdj@mstdn.social
(DIR) More posts by pmdj@mstdn.social
(DIR) Post #B2c1yPewAUErGUjdZo by justine@snac.smithies.me.uk
2026-01-24T14:17:33Z
0 likes, 0 repeats
I'm after some advice from folk that use #Git . I have my own self hosted Git server and I have one repository that I'd like to empty of all content and history. I know I can just delete the remote repository and recreate it again starting a fresh. But would using git push --force <remote> <branch> not just do the same by overwriting the remote repository with the locals contents ? Or could I end up with files in the remote that are not in my local ???I should also say that I am the only person that pushes to this remote repo too. Any help or advice is very much appreciated and thank you.
(DIR) Post #B2c2dDBfRa6iSMUzCq by nafmo@social.vivaldi.net
2026-01-24T14:21:57Z
0 likes, 0 repeats
@justine You'll end up with objects from both the old and new files in the object store, but that should sort itself out over time when you run gc on it, anything not referenced anywhere will eventually be cleaned out.
(DIR) Post #B2c2dEHjMWYFrSLLIO by justine@snac.smithies.me.uk
2026-01-24T14:24:48Z
0 likes, 0 repeats
Thank you, So would you recommend that way or just delete the repo and start afresh ?
(DIR) Post #B2c2o1Hs1nAgjcYOtU by pmdj@mstdn.social
2026-01-24T14:24:39Z
0 likes, 0 repeats
@justine Yeah, that'll work. In fact you can have multiple branches in the same repository which share NO history whatsoever.Note that overwriting branches like this doesn't actually delete the previous commits however. There will still be ways to get at commits that are not part of any live branch's history, at least until they're properly deleted by later pruning/GC runs.
(DIR) Post #B2c2o28Ksj8fML6Ifg by justine@snac.smithies.me.uk
2026-01-24T14:26:10Z
0 likes, 0 repeats
Thank you Phil. ๐
(DIR) Post #B2c3zTLY901OtnIdsm by pmdj@mstdn.social
2026-01-24T14:30:23Z
0 likes, 0 repeats
@justine Any clones of this repository that have it set as a tracking remote are of course in for a bad time when they try to pull. But I'm guessing you've already accounted for that. (I *think* they'll complete the fetch and bail out when they can't fast-forward or merge the upstream branch due to lack of common ancestor; clients other than the stock git CLI client might throw a wobbly.)
(DIR) Post #B2c3zUTNxLsqONyPjc by justine@snac.smithies.me.uk
2026-01-24T14:40:02Z
0 likes, 0 repeats
So am I better to delete the repo and recreate then or just go with the force push ?
(DIR) Post #B2c49G7iA8cYmeUf5M by gumnos@mastodon.bsd.cafe
2026-01-24T14:35:52Z
0 likes, 0 repeats
@justine As @nafmo notes, the old loose objects will be present but benign until GC happens. Normal usage should automatically gc the bare repo in the fullness of time, but you could theoretically force it.If you are comfortable with destroying and recreating the bare repo (I do that plenty when testing things) then both will eventually quiesce into roughly the same state. The only concern would be if you had pushed branches to the bare repo, then deleted them locally, but then want to re-clone them locally. Deleting the repo would lose those branches that you don't already have locally. But it doesn't sound like that's the case, so not a major concern.
(DIR) Post #B2c49Hrpg96kBz50c4 by justine@snac.smithies.me.uk
2026-01-24T14:41:27Z
0 likes, 0 repeats
Thank so much for your detailed explanation Tim. ๐CC: @nafmo@vivaldi.net
(DIR) Post #B2c70EgURXoLZp9Mae by justine@snac.smithies.me.uk
2026-01-24T15:13:05Z
0 likes, 0 repeats
So I'm guessing that I could do the following from within the remote Git repository to delete it's history and contents, Allowing me to start a fresh by pushing new files from the local repo ???git branch -D mastergit checkout --orphan mastergit rm -rf *
(DIR) Post #B2cAf4Asit6siUWhtY by justine@snac.smithies.me.uk
2026-01-24T15:54:47Z
0 likes, 0 repeats
Still trying to work out what's best. So I have a Git repo that is full of dotfiles and I wish to use this repo. Only thing is I setup my computer again and I do not want to clone the contents to my computer as I have remade most files with loads of fixes which were never committed to any repo. So I want to start adding them back to the remote repo but I know it will complain.Is this what I'd use git push --force origin <branch-name> for to allow me to push my newer local changes to the remote thereby overwriting the matching files if they already exist in the remote Git repo ?
(DIR) Post #B2cBKp3dJkeNzk2yXY by pmdj@mstdn.social
2026-01-24T15:58:39Z
0 likes, 0 repeats
@justine OK, now I'm wondering whether we're on the right track here at all. Do you have a good reason to wipe the history? Or are you basically saying you want to retain history but you didn't start with a clone of the repository but re-filled it with files by hand, so you're worried you're going to lose that stuff if you now start from your latest revision?
(DIR) Post #B2cBKq69RsG7DqEV6W by justine@snac.smithies.me.uk
2026-01-24T16:02:19Z
0 likes, 0 repeats
I think I'm a little confused here so I'll try explain. I have a remote Git repo with dotfiles in it. I have setup a new computer and made my home directory the repo like so.https://justine.smithies.me.uk/dotfiles.htmlI have changed so much locally on my computer that I do not want to lose any changes that I have made locally at all. I do not care about history on the remote but I'd like to be able to add back or overwrite what is on the remote with the copies in my local ( computers ) repo .Does that make sense as in my head it does ????
(DIR) Post #B2cBo6PLt9SsChARsW by pmdj@mstdn.social
2026-01-24T16:04:23Z
0 likes, 0 repeats
@justine Because `git push --force` is all about rewriting history, and not about deleting or overwriting individual files.Personally, if I was in your situation, I'd probably want to keep the history, just so I could later look back at how I had previously done something. So the new version should just be a new commit on top of the old history.If that's the case, your question purely becomes one of wrangling the CLI client to make sure it commits everything just so without losing it.
(DIR) Post #B2cBo7CGxGb2eQ3W88 by justine@snac.smithies.me.uk
2026-01-24T16:07:38Z
0 likes, 0 repeats
Yes agreed but once I setup my home dir as a git repo that has no history and try committing say a file like .kshrc then pushing it to the remote then isn't Git going to complain about the differences and there being no matching history locally ? How do I overcome that as I cannot do git clone or pull as that will mess up my working local files.
(DIR) Post #B2cCVjhdfOM8WjWkQi by pmdj@mstdn.social
2026-01-24T16:11:12Z
0 likes, 0 repeats
@justine Yeah, I understand your problem now.I'm going to have to think about this one and look some things up I think. Note that the issue isn't that the file already exists, but that your local commit isn't sharing history with upstream.One option you have is to start with a fresh history but put it in a new branch, so the old history continues to exist in the old branch.There's probably a way to stack them, but it's a rare operation so I don't know off the top of my head how to do it.
(DIR) Post #B2cCVkgG20qTYjt9uq by justine@snac.smithies.me.uk
2026-01-24T16:15:27Z
0 likes, 0 repeats
Sorry I know I like to make things difficult for myself rather than taking the easy route and starting afresh but I can't help myself. Thank you for your help though. ๐
(DIR) Post #B2cR3Jz5C1vHxxayCu by njr@mathstodon.xyz
2026-01-24T18:53:29Z
0 likes, 0 repeats
@justine I think youโre much better deleting the repo and recreating if you donโ want the history.If you do, as backup, I would rename the remote and recreate the new (bare) repo.Possibly rename the local one, clone the remote and copy over before pushing for no history anywhere. Very safe and reversible.
(DIR) Post #B2cR3LgirGQPFb1Kro by justine@snac.smithies.me.uk
2026-01-24T18:56:17Z
0 likes, 0 repeats
Thanks Nick I just created a new repo in the end.