cd /media/run/usb-drive/my-backup-repo && git init --bare
Bare repositories don't have a working directory. You can still git clone / git pull from them to get the contents. You can also git push to them without clobbering any "local changes" (there aren't any).More detail here:
https://www.atlassian.com/git/tutorials/setting-up-a-reposit...
So in the end, simple is simple :) Unless you're creating remote repositories at scale, you probably won't notice a difference in storage usage.
~/temp/a:master $ git push backup
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 212 bytes | 212.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
...
To ../b
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '../b' git clone --mirror
git clone --bare
git push --mirror
git push --all
"Is `git push --mirror` sufficient for backing up my repository?"
https://stackoverflow.com/questions/3333102/is-git-push-mirr... :> So it's usually best to use --mirror for one time copies, and just use normal push (maybe with --all) for normal uses.
git push: https://git-scm.com/docs/git-push
git clone: https://git-scm.com/docs/git-clone
Woah, that's really cool, didn't know about that. This is really useful! Thanks for sharing that.
Also, the `master` is just an example, it works for `main` as well, don't worry :) The created git repository on your usb-stick works like a regular git repository, you can use whatever branch names you want.
Btw, way to focus on the absolutely least interesting part of my comment, what I chose to name the branch...
It's also two less characters and one less syllable.
We all know why this change exists, and why some people will attempt to persuade others of it's superiority. It is, however, just silly virtue signaling, and it's exhausting to hear and read.
It would require some very irrational and underdeveloped reasoning to assert this word has anything to do with oppression in 2023. There is no negative connotation, except in those who wish to perpetuate some weird sensation of altruism... ie. no one is safer or feels better simply because you choose to call it "main" rather than "master".
You should be aware that complaints about supposed virtue signaling are equally exhausting.
Which is just the thing, really. It makes no one feel better. It makes the privileged speaker feel better, with a false sense of virtue. It's a "look at how great I am" signal, nothing more.
No one is harmed or made to feel bad by using the word master. Sometimes the adults have to be present in the room, it seems.
Saving 2 characters is an equally silly excuse, but at least it has a realistic rationale. To that end, why stop at main - why not just 'm'? You can call it whatever you want in git.
Good design :)
I totally agree.
> Good design
Having one default instead of two is better design.
Clearly some feel better.
I personally like the name “main” better.
But it is truly a pain in the neck that different pieces of software and even different distributions of the same software now disagree about the default.
I’ve got a handful of active projects that go together that differ on master/main because they were created by different softwares.
I’d prefer “hitler” if everyone could just agree to always pick that. GitHub are the big pushers of this culture change. If they succeed, I salute them.
GitHub practically invented the exact situation you're experiencing now by changing to main for all new repos.
Git itself still defaults to master. Everything else is not the default and is the root cause for the uncertainty.
I believe new GitHub accounts now have that set to main.
That opens some interesting possibilities.
Cheers
If a snapshot suffices, a once off "git push" or "git clone" works (but that's not too far off from downloading a tar ball, is it?). If you want to have a up-to-date local copies of multiple repos, a SQLite-backed Gitea instance is the simplest solution.
An added bonus to using Gitea is flexibility in mirroring LFS objects, which can be sent to S3 or minio
Agree to disagree :)
This seems like the simplest solution:
git remote set-url --add --push origin [email protected]:my-user/my-repo.git
git remote set-url --add --push origin /backups/repos/my-user/my-repo.git
Now when you push to origin, it pushes to your local backup as well, everything up to date, no external sosftware at all :)Thanks dabber for sharing this trick (https://news.ycombinator.com/item?id=34603174)
Just a tip: no need to use gitea if you want to replicate a git repository to somewhere else on disk/other disk.
Just do something like this:
And now you have a new repository at /media/run/usb-drive/my-backup-repo with a master branch :) It's just a normal git repository, that you also can push to over just the filesystem