Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What’s the most idiomatic way to implement a “floating tag” in Git?

Tags:

git

I keep my website in a Git repository. It’s just a small personal site so there’s no fancy automation; I’ll make a bunch of changes and then periodically push the site to the server using jekyll-s3. I do like to keep track of which revisions have been uploaded and which haven’t, and right now I have a branch called pushed into which I merge master each time I upload to the server. (If any other branches are involved I merge everything into master before pushing, so that only master ever gets merged into pushed.)

This works well enough, but it seems weird to me to be using an “entire” branch when all I care about is marking one commit at a time as “this has been pushed”. (Yes, I know that branches are considered very lightweight in Git.) Terminology-wise it seems like I want to “tag” the latest commit each time I upload to the server—except that in Git, a tag is supposed to be an immutable reference to one specific commit. Is keeping a branch called pushed the most idiomatic way to do what I’m trying to do, or is there a better way?

like image 256
bdesham Avatar asked Sep 16 '25 20:09

bdesham


2 Answers

Tags in Git come in two flavours: "lightweight" and "annotated". A lightweight tag is very much like a branch head, it is just a name that points to a specific commit and nothing more. It's straightforward to change the commit id that a lightweight tag points to.

An annotated tag has its own sha1 id, timestamp, committer, description, optionally a signature, and also points to a specific commit. I think this is the kind of tag you're referring to when you say "supposed to be an immutable reference".

like image 194
Greg Hewgill Avatar answered Sep 18 '25 18:09

Greg Hewgill


If I understood correctly, you want to have a reference to your last update on the website, right? Well, branching is in fact what they do, but not with the naming you have done.

As you may know, there are two major ways for development with version control systems:

  • master is development branch. In this case, the stable releases are certain tags.
  • master is the stable branch. In this case, you have other branches for development. When you want to add your feature to master, you merge master with your own branch and test it. If it worked, you merge the results with master and push it to your website.

What you are talking about is in fact the second method, where you have a stable branch named pushed and you keep it stable (uploaded, working, whatever property you want) at all times.

So, yeah what you do already exists, however more idiomatically, they keep master as that stable branch rather than some other branch (for example named pushed). It's the same concept though.

Edit: What I'm saying is that, whenever you want to upload your changes to your website, merge whatever you have in master (or pushed if you like), and then upload it. This way, the last commit of master (or pushed) is the last upload of the website.

like image 21
Shahbaz Avatar answered Sep 18 '25 19:09

Shahbaz