Hacker News new | ask | show | jobs
by henshao 597 days ago
These should be aliases in your git config.

    git config --global alias.<cmd> <cmd>
I'm really trying to understand, and not to be too negative. I get coming up with a solution to a problem, and finding it neat locally. But before posting to HN, one might realize that these solutions that git provides existing tools for is better than maintaining this.

I'm also confused by all the comments just blindly commenting in the affirmative or providing suggestions. Are we all bots?

7 comments

But before posting to HN, one might realize that these solutions that git provides existing tools for is better than maintaining this.

One might. But not everybody knows about those existing tools. Taking myself as an example: I've been using Git since nearly the time it was released and I had no idea that git had aliasing built in. Sometimes things just never come up and people don't find out about them. shrug

Hi! Author here. Some of these can indeed be an alias, others.. not so much. `git-root` for example is more-or-less a one-liner, meanwhile `git-mode-restore` is a ~840 loc python script. I do use git aliases but trying to do anything non-trivial in them seems rather counter-productive so I'm confused about everyone suggesting it :P
Hey. I think my point is that writing and maintaining 900 lines of code is an option, and another option is to figure out how to not write and rely on 900 lines of code. I looked through git-more-restore a bit and I think you're trying to reverse permission changes in your working branch back to what's on HEAD.

I think a way to do this is to not let git track that in the first place, with some variation of:

    git config core.fileMode false
via: https://stackoverflow.com/questions/1580596/how-do-i-make-gi...

or

https://stackoverflow.com/questions/2517339/how-to-restore-t...

It seems to me like a shallow reading and dismissal of your work. Which is sad. For what it's worth I'll be giving it a go as soon as I'm back at work on Tuesday.
What would the alias command be for

  git-delete-gone-branches
?

EDIT: I saw your other comment (incorrectly) claiming that git remote prune origin will do the job. I don't know of any git trickery that can do the job. And believe me I'd love it if there was something.

Thanks for keeping me honest. I just read the first line of the stackoverflow, but the one liner is still in the comments. I just tested it.

https://stackoverflow.com/questions/7726949/remove-tracking-...

    git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d
That looks fine and will generally work, except when the current branch is one of the ones to be deleted.

The script in OP handles that edge case by switching to the main branch before deleting. That may or may not be intuitive but I think it's a reasonable response. The script also prints error messages for various other bad inputs. Once you strip all that out it's only a few lines long.

I'm going to assume you have about as many years of experience as me based on your profile, but if you're going to argue that maintaining this script - for the sole convenience of deleting a branch out from underneath you - is worth it, then there's nothing more I can do to help you.
You're being really dismissive. Handling bad inputs and edge cases, and including help texts, is the sort of requirement that necessitates moving away from one-liners towards a more structured repository.
Same as mine. I also pass the `-r` flag to xargs so it doesn't run if there are no inputs.
I have an alias "git prune-branches" that deletes branches that remote has deleted. Is that what you are loking for? Cannot check the code right now but will try to get back tomorrow.
If you're willing to report back I'd be very grateful.
The trouble is that git aliases aren't composable and you can't install them. Each installation has its own aliases. If you are in a new machine you must define the aliases yourself. This also makes git aliases have poor discoverability.

Compare this with another tool that lets people extend its own command, cargo. You can do cargo install <something> and then run cargo <something>.

As a culture we need to move away from “just write these things yourself/copy these aliases and maintain them”. It makes things too much of a rite of passage.

No, I have never used NPM directly. Why do you ask?

If I see a git thread, I tend to semi-spam my git aliases because so few people realize that they can customize git's command line behaviour.
Yeah I am just finding it hard to believe that there are so many people who don't.

Maybe we are 10x engineers w.r.t. git aliases. Congratulations

Most tech folks in IT that I've known tend to just accept defaults, whether they're in vscode, a command line, or joining a new project. They don't seem to think in terms of "this is annoying/inefficient, how can I make it better?"

I should get "10x engineer with my git aliases" put onto a t-shirt :)

You’re suggesting not to use a functionality built into got from early days that naming a script git-something and putting it on your PATH gives you a sub command of “git something”.

Why do you disagree with this early decision from git?

Came here to say this.

I looked at 1/3 of the scripts and not one _adds_ functionality, they only add interfaces for existing functionality.

I hate to say this but I feel like this post got upvoted simply for being hit-adjacent.

I wonder if voting on the front page is a bad setup.