6 comments

  • AdieuToLogic43 days ago
    On a related note, git supports incorporating custom commands via executables available in the `PATH` having the naming convention of:<p><pre><code> git-&lt;command name&gt; </code></pre> Where &quot;command name&quot; in this case would be `archive-branch` and could be defined thusly:<p><pre><code> #!&#x2F;bin&#x2F;sh # git-archive-branch git_branch=&quot;${1:-$(git branch --show-current)}&quot; git co main &amp;&amp; git tag archive&#x2F;$git_branch $git_branch &amp;&amp; git branch -D $git_branch </code></pre> It then could be invoked the same as the alias:<p><pre><code> git archive-branch ...</code></pre>
    • rurban43 days ago
      Oh oh. Your co alias leaked :)
      • cyco13043 days ago
        Not the gp but I can&#x27;t live without co&#x2F;ci&#x2F;br now.
        • rurban43 days ago
          Sure. I cannot imagine anyone living without the most common aliases anymore, but in a script you either need to alias again, or expand. Happens so often to me also.
    • vbezhenar43 days ago
      Why is this useful? Why would someone care about typing `git archive-branch` instead of `git-archive-branch`?
      • kreetx43 days ago
        Consistency: not needing to remember under which alternative methods any command was found under.
  • ziml7743 days ago
    Seems like a sensible way to archive branches. It&#x27;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&#x27;s archived, you don&#x27;t need the pointer updating mechanism.
    • progval43 days ago
      &gt; A tag is a pointer that always refers to the same commit<p>It&#x27;s not guaranteed not to change. The UI just makes it harder to update.
      • QuantumNomad_43 days ago
        And anyone whose coworkers replace tags on a regular basis will be familiar with the following message from git when pulling changes:<p>would clobber existing tag<p>Really wish my coworkers would leave old tags as they were heh.
        • az09mugen42 days ago
          I have a somewhat different use case, where a work project has a moving &quot;latest&quot; tag. I discovered then the --force param with git fetch --tag
        • toenail43 days ago
          A hook should be able to prevent that
          • monkpit43 days ago
            Hooks only keep honest people honest :) and an LLM will happily clobber a tag and skip hooks while the user just spams “accept”.
            • mroche43 days ago
              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&#x27;m still waiting for the day where tags are immutable by default with no option exposed to change it.<p>I&#x27;m sure that would cause problems for some, but transitive labels already exist in Git: branches.
              • MadnessASAP43 days ago
                I dont find the idea of a immutable &quot;descriptive&quot; tag or branch to be that useful (I also dont find the differentiation of tags and branches to be useful either) I&#x27;ve seen plenty of repositories where tags end up being pretty ambiguous compared to each other or where &quot;release-20xx&quot; 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.
                • mroche43 days ago
                  I 100% agree on the latter (the tag != release is more of a project management issue), and the same concept applies to containers and their digest hashes. The main issue at the end of the day is the human one: most people don&#x27;t like looking at hashes, nor do they provide context of progression. I would say &quot;give both&quot; and make sure they match on the end user side of things, but tags are the most common way (open source) software releases are denoted.
              • Buttons84043 days ago
                As long as we can create and delete tags, they will never be immutable, right?
                • mroche43 days ago
                  The purpose of the forge is to be able to prevent this. Protected tags are usually a feature which provides a way to mark tags as untouchable, so removal would require a minimum level of trust to the repository on the platform. Otherwise, attempts to push tag deletions or changes for tags matching the protected pattern would be rejected&#x2F;ignored.<p>Of course, the repository owner has unlimited privilege here, hence the last part of my prior comment.
              • jaggederest43 days ago
                Tags are just a text file with a name and the sha of the tag object (with the commit and some metadata&#x2F;signatures as contents), last I checked. It&#x27;s deliberately simple and thus almost impossible to actually lock it down in concrete terms.<p>Packed refs are a little more complicated but all of the storage formats in git are trivial to manually edit or write a tool to handle, in extremis.
                • mroche43 days ago
                  That&#x27;s the purpose of the forge platform, to provide a way to prevent changes to these files from being accept into the source repository. For example:<p><a href="https:&#x2F;&#x2F;docs.github.com&#x2F;en&#x2F;repositories&#x2F;configuring-branches-and-merges-in-your-repository&#x2F;managing-rulesets&#x2F;about-rulesets" rel="nofollow">https:&#x2F;&#x2F;docs.github.com&#x2F;en&#x2F;repositories&#x2F;configuring-branches...</a><p><a href="https:&#x2F;&#x2F;docs.gitlab.com&#x2F;user&#x2F;project&#x2F;protected_tags&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.gitlab.com&#x2F;user&#x2F;project&#x2F;protected_tags&#x2F;</a><p><a href="https:&#x2F;&#x2F;forgejo.org&#x2F;docs&#x2F;latest&#x2F;user&#x2F;protection&#x2F;#protected-tags" rel="nofollow">https:&#x2F;&#x2F;forgejo.org&#x2F;docs&#x2F;latest&#x2F;user&#x2F;protection&#x2F;#protected-t...</a>
            • venturecruelty43 days ago
              Can&#x27;t solve culture problems with technology, but we all know that by now, right?
            • Denvercoder943 days ago
              That&#x27;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&#x27;t have admin access).
              • toenail43 days ago
                Thanks, apparently most people here aren&#x27;t familiar with server-side hooks.
    • paulddraper43 days ago
      Correct.<p>One is refs&#x2F;heads&#x2F;&lt;name&gt; and the other is refs&#x2F;tags&#x2F;&lt;name&gt;<p>Branches are expected to change. When a commit is authored, HEAD (the current branch) updates to that commit.<p>Tags are expected not to change (though they can).
      • lucasoshiro43 days ago
        Other difference (actually, more like a consequence of what you said) is that Git keeps reflogs for branches but not for tags
  • tonymet43 days ago
    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.<p>`git push —all backup` will record all of your refs and tags<p>If you are archiving branches in your own rep, prefix with `ar&#x2F;` so you can grep -v to conceal them.<p>See also `git notes` to record metadata an against a commit without changing the commit
  • derriz43 days ago
    &gt; Important note: the strange magic requires the official git completion script.<p>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.
  • kazinator43 days ago
    I don&#x27;t see the point of this. A git branch is already a kind of tag.<p>How about just<p><pre><code> # rename branch to archive&#x2F; prefix to indicate it is archived git branch -m foo-branch archive&#x2F;foo-branch</code></pre>
    • figmert43 days ago
      Branches are expected to change, tags are not. Tags are also mildly harder to change. A tag seems more apt for an archived branch. So I sort of see where OP comes from.
      • Zardoz8443 days ago
        Yeah. But WHY taging instead of renaming the branch ? I don&#x27;t say if it is a good or bad idea. But I would like to know why.
        • cachvico43 days ago
          You can accidentally push to a branch. You can&#x27;t accidentally push to a tag.
        • rolandog43 days ago
          If you read the article, it credits a reddit thread as the source of inspiration; the thread ultimately points to a StackOverflow answer [0] which may offer a better argument as to why they liked yo use this pattern.<p>[0]: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;1309934" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;1309934</a>
    • kjksf43 days ago
      Because in git tooling (be it github.com or a tui&#x2F;gui client like lazygit), git branches are shown more prominently because the expectation is that a branch is something you actively work on (if you&#x27;re finished with a branch, you delete it).<p>If you don&#x27;t anticipate working on a branch but you want to preserve the code you leave it but it starts to clutter that prominent &quot;active&quot; space in most git tools.<p>This allows you to preserve the code (if you ever want to look at it again) while also de-cluttering the prominent &quot;branches&quot; view.
      • kazinator43 days ago
        How would this argument change if <i>git branch</i> recognized the &quot;archive&#x2F;&quot; convention, or had some other mechanism, such that archived branches are concealed from view unless -a&#x2F;--all is given?<p>I like the idea that branch names starting with . (period) are considered hidden, similarly to files in Unix.
    • MaulingMonkey43 days ago
      FWIW, this is what I do, although typically with the prefix `dead&#x2F;`, unto which I abandon ideas and misdirected refactoring with reckless abandon.
  • PunchyHamster43 days ago
    How often did you go back to the archived tagches that are older than say, 6 months ? Seems very niche, unless dunno, there are no version tags in the repo.
    • yawaramin43 days ago
      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&#x2F;declined. We&#x27;ve never had a need to archive branches.
      • phire43 days ago
        It seems very useful for archiving branches that never got merged.<p>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.<p>Currently, those abandoned branches have been polluting my branch list. In the past I have cloned the repo a second time just to “archive” them. Tags seem like a better idea.
        • skydhash43 days ago
          I don’t think I’ve ever returned to a branch that I can easily rebase on top of the main branch. And if I really wanted to, I’d prefer to extract a patch so that I can copy the interesting lines.<p>Any branch older than 6 months is a strong candidate for deletion.
        • dotancohen43 days ago
          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.
          • matijsvzuijlen43 days ago
            What made you decide to squash when merging instead of leaving the commits in the history so you can always bisect?
            • quesera43 days ago
              Not GP, but we do the same. Branches become the atomic unit of bisection in master, but the need is extremely rare. I think because we have good tests.<p>We also keep merged branches around. This has never happened, but if we needed to bisect at the merged-branch level, we could do that.<p>I know squash-merge isn&#x27;t everyone&#x27;s cup of tea, but I find it to be simpler and clearer for the 99+% case, and only slightly less convenient for the remainder.
            • dotancohen43 days ago
              The range reason your history textbook is not infinitely long. The longer something is, the less digestible. When we need more granularity, it&#x27;s there in the branches.
        • ervine43 days ago
          Wonder if it&#x27;s worth squashing in the branch, merging to main, then immediately reverting.<p>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.<p>Dunno if it&#x27;s worth polluting history, just thinking out loud.
        • PunchyHamster43 days ago
          let it go. You will not bother fixing those to work with master.<p>It just moves trash from branch list to tag list.
      • fragmede43 days ago
        if you&#x27;re deleting branches then why would you need to archive them? What would you even archive if you&#x27;re deleting them? My deeper question is why are you deleting them in the first place though?
        • yawaramin42 days ago
          We&#x27;re deleting them because we don&#x27;t need them and we like keeping things tidy.
    • venturecruelty43 days ago
      Believe it or not, some people need to use software more than six months old.