Live data from Hacker News

Archiving Git branches as tags

etc.octavore.com

11–20 of 49 posts

Re: Archiving Git branches as tags

#11
post #4

Earlier quoted context omitted.

> A tag is a pointer that always refers to the same commit It's not guaranteed not to change. The UI just makes it harder to update.

And anyone whose coworkers replace tags on a regular basis will be familiar with the following message from git when pulling changes: would clobber existing tag Really wish my coworkers would leave old tags as they were heh.

A hook should be able to prevent that

Re: Archiving Git branches as tags

#12
IMO a cleaner way to do this is with a headless remote, either on disk or “backed up” on a server. `git push —-all` won’t delete refs on the remote, so you don’t have to do any additional work to record or recover them.

`git push —all backup` will record all of your refs and tags

If you are archiving branches in your own rep, prefix with `ar/` so you can grep -v to conceal them.

See also `git notes` to record metadata an against a commit without changing the commit

Re: Archiving Git branches as tags

#13
> Important note: the strange magic requires the official git completion script.

I dislike the official git completion script because it’s so slow when working with large repos. On macOS - because of vagaries of the way its file system works - with large repos it’s effectively unusable. Hint to completion script writers: if your “smart” completion ever takes seconds, it’s worse than useless and far worse than “dumb” filename completion.

Re: Archiving Git branches as tags

#14
post #11

Earlier quoted context omitted.

And anyone whose coworkers replace tags on a regular basis will be familiar with the following message from git when pulling changes: would clobber existing tag Really wish my coworkers would leave old tags as they were heh.

A hook should be able to prevent that

Hooks only keep honest people honest :) and an LLM will happily clobber a tag and skip hooks while the user just spams “accept”.

Re: Archiving Git branches as tags

#15
post #6

Earlier quoted context omitted.

It seems very useful for archiving branches that never got merged. Sometimes I work on a feature, and it doesn’t quite work out for some reason or another. The branch will probably never get merged, but it’s still useful for reference later when I want to see what didn’t work when taking a second attempt. Currently, those abandoned branches have been polluting my branch list. In the past I have cloned the repo a seco…

I sometimes leave merged branches around for quite a while, because I squash them when I merge to master and sometimes when tracking down a bug the ability to bisect very handy.

What made you decide to squash when merging instead of leaving the commits in the history so you can always bisect?

Re: Archiving Git branches as tags

#16
post #6

Earlier quoted context omitted.

True. At work our flow is to tag commits that we want to mark as release candidates and delete feature branches after their PRs are merged/declined. We've never had a need to archive branches.

It seems very useful for archiving branches that never got merged. Sometimes I work on a feature, and it doesn’t quite work out for some reason or another. The branch will probably never get merged, but it’s still useful for reference later when I want to see what didn’t work when taking a second attempt. Currently, those abandoned branches have been polluting my branch list. In the past I have cloned the repo a seco…

Wonder if it's worth squashing in the branch, merging to main, then immediately reverting.

Now the work is visible in history, branch can be deleted, and anyone in the future can search the ticket number or whatever if your commit messages are useful.

Dunno if it's worth polluting history, just thinking out loud.

Re: Archiving Git branches as tags

#17
post #14
post #11

Earlier quoted context omitted.

A hook should be able to prevent that

Hooks only keep honest people honest :) and an LLM will happily clobber a tag and skip hooks while the user just spams “accept”.

Luckily commonly used forges for collaboration have the ability to make tags immutable. Any repository where multiple people collaborate on a project should have that feature enabled by default. I'm still waiting for the day where tags are immutable by default with no option exposed to change it.

I'm sure that would cause problems for some, but transitive labels already exist in Git: branches.

Re: Archiving Git branches as tags

#18
post #2

Seems like a sensible way to archive branches. It's not like a tag and branch are actually very different anyway, right? A tag is a pointer that always refers to the same commit while a branch is a pointer that follows commits forward. And for something that's archived, you don't need the pointer updating mechanism.

Correct.

One is refs/heads/ and the other is refs/tags/

Branches are expected to change. When a commit is authored, HEAD (the current branch) updates to that commit.

Tags are expected not to change (though they can).

Re: Archiving Git branches as tags

#19
post #17
post #14

Earlier quoted context omitted.

Hooks only keep honest people honest :) and an LLM will happily clobber a tag and skip hooks while the user just spams “accept”.

Luckily commonly used forges for collaboration have the ability to make tags immutable. Any repository where multiple people collaborate on a project should have that feature enabled by default. I'm still waiting for the day where tags are immutable by default with no option exposed to change it. I'm sure that would cause problems for some, but transitive labels already exist in Git: branches.

I dont find the idea of a immutable "descriptive" tag or branch to be that useful (I also dont find the differentiation of tags and branches to be useful either) I've seen plenty of repositories where tags end up being pretty ambiguous compared to each other or where "release-20xx" does not actually point to the official 20xx release. Immutable references are more typically handled by builders and lockfiles to which Git already has a superior immutable reference system, the commit hash.

Re: Archiving Git branches as tags

#20
post #14
post #11

Earlier quoted context omitted.

A hook should be able to prevent that

Hooks only keep honest people honest :) and an LLM will happily clobber a tag and skip hooks while the user just spams “accept”.

That's true for local hooks, but neither a dishonest person nor an LLM can bypass a pre-receive hook on the server (as long as they don't have admin access).
Post reply on HN