[HN Gopher] ToolGit: A collection of scripts that extend Git wit...
       ___________________________________________________________________
        
       ToolGit: A collection of scripts that extend Git with various sub-
       commands
        
       Author : ahmetsait
       Score  : 58 points
       Date   : 2024-11-03 17:32 UTC (5 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | porridgeraisin wrote:
       | https://gist.github.com/romainl/a3ddb1d08764b93183260f8cdf0f...
       | 
       | This script in your path means that after you say pull code and
       | have merge conflicts, "git jump" will open vim with the quickfix
       | list populated with the locations of the conflicts.
        
         | gchamonlive wrote:
         | > NOTE: The original git-jump now supports the flag --stdout,
         | which makes this hack redundant, but I will keep it for
         | posterity
         | 
         | This update is from May 2023
        
         | ttyprintk wrote:
         | Jump is distributed under /usr/share/git-core/contrib or
         | something.
        
         | secondcoming wrote:
         | How's this different to 'git mergetool'?
        
       | can16358p wrote:
       | "git-delete-gone-branches" is exactly what I've been needing,
       | will give it a try soon!
        
         | henshao wrote:
         | "git delete gone branches" is a one liner that you can google.
         | first stack overflow result gives you the answer:
         | git remote prune origin
         | 
         | Why would you use this 50 line script to do the same?
        
           | n4r9 wrote:
           | This only removes references to remote branches. See e.g.
           | [0]. The command in OP operates on local branches.
           | 
           | [0] https://stackoverflow.com/questions/20106712/what-are-
           | the-di...
        
             | henshao wrote:
             | Just for anyone else following along..you're right. Here it
             | is.                   git fetch -p && git branch -vv | awk
             | '/: gone]/{print $1}' | xargs git branch -d
        
       | stephenr wrote:
       | Most of these would be better as aliases in your global hit
       | config file.
       | 
       | Several are 30+ lines of boilerplate to run a git one-liner.
        
         | gchamonlive wrote:
         | It struck me the same, many seem like aliases such as `gc!`
         | from oh-my-zsh.
        
         | henshao wrote:
         | This was my first thought as well. This might be an indictment
         | of how obscure/confusing some git invocations are...hence the
         | alias to human readable names.
         | 
         | It is kind of interesting that there is much interest, work and
         | maintenance on these over-complications...There seems to be a
         | related repo - git-extras - that does the same as this repo,
         | and has 17k stars.
        
       | kenmacd wrote:
       | Obligatory mention of https://github.com/tj/git-
       | extras/blob/main/Commands.md for more/similar commands.
       | 
       | Especially useful to me is `git bulk` to apply a command to all
       | the git repos under the directory, and `git ignore "bin/"` to
       | quickly add something to the `.gitignore` file.
        
         | euroderf wrote:
         | > `git bulk` to apply a command to all the git repos under the
         | directory
         | 
         | There is also: gitup . -e "arbitraryShellCommand withArg"
        
         | ahmetsait wrote:
         | I like these a lot! It seems like git-extras is pure bash
         | allowing it to work out of the box without any dependencies but
         | I would probably go mad if I had to implement1 reading/writing
         | git index2 in bash.
         | 
         | 1
         | https://github.com/ahmetsait/toolgit/blob/58713ead5abc060510...
         | 
         | 2 https://git-scm.com/docs/index-format
        
       | otikik wrote:
       | This needs a "git-track". Make the current branch track the one
       | in origin with the same name, if it exists
        
         | gchamonlive wrote:
         | In oh-my-zsh you have `ggsup` which is an alias for `git branch
         | --set-upstream-to=origin/$(git_current_branch)`.
         | `git_current_branch` is also a function that is bundled with oh
         | my zsh.
        
         | gtirloni wrote:
         | [push]         autoSetupRemote = true
        
       | bloopernova wrote:
       | Some of my git aliases might be useful to folks here (I post them
       | from time to time on git threads)
       | 
       | Time to share my gitconfig aliases again :D                 lol =
       | !git --no-pager log --graph --decorate --abbrev-commit --all
       | --date=local -25 --pretty=short       sw = !git checkout $(git
       | branch -a --format '%(refname:short)' | sed 's~origin/~~' | sort
       | | uniq | fzf)       lc = !git rev-parse HEAD       rb = !git for-
       | each-ref --sort=-committerdate refs/heads/
       | --format='%(refname:short) %(objectname:short)
       | %(committerdate:format:%F)' | column -t       fza = "!git ls-
       | files -m -o --exclude-standard | fzf -m --print0 | xargs -0 git
       | add"       gone = "!f() { git fetch --all --prune; git branch -vv
       | | awk '/: gone]/{print $1}' | xargs git branch -D; }; f"
       | root = rev-parse --show-toplevel       oldest-ancestor = !zsh -c
       | 'diff -u <(git rev-list --first-parent "${1:-main}") <(git rev-
       | list --first-parent "${2:-HEAD}") | sed -ne \"s/^ //p\" | head
       | -1' -       diverges = !sh -c 'git rev-list --boundary $1...$2 |
       | grep "^-" | cut -c2-'       dlog = "!f() {
       | GIT_EXTERNAL_DIFF=difft git log -p --ext-diff $@; }; f"
       | 
       | Some of these I don't use much, but others I use every day:
       | 
       | "git fza" (aliased to "ga") shows all unstaged files in fzf and
       | you can use space to toggle them, then hitting enter finishes
       | adding/staging them. This is great for selecting some files to
       | stage. I use this one every day, it makes my workflow just a
       | little better :)
       | 
       | "git gone" deletes local branches that don't exist in the remote.
       | I just saw in this thread that _git remote prune origin_ might do
       | the same thing, I need to test that.
       | 
       | "git lol" is a log alias.
       | 
       | "git oldest-ancestor brancha branchb" does what it says.
       | 
       | "git root" is part of an alias "gr" which runs "cd $(git root)".
       | That takes you to the project root, and "cd -" will take you back
       | to your previous location.
       | 
       | "git dlog" shows a detailed commit log.
       | 
       | "git lc" just shows the last commit.
       | 
       | "git rb" shows recent branches. Piping it to "| sort -k3" will
       | sort by date. (I really need to update that!)
       | 
       | "git sw" shows branches in fzf, hit enter on one and you checkout
       | that branch.
        
         | bloopernova wrote:
         | If you use oh-my-zsh's git plugin, it defines a huge number of
         | aliases that minimize the characters you have to type in. I use
         | these mostly every day:                 gl = git pull       gp
         | = git push       ga = aliased to git fza from my above comment
         | gc = "git commit -m " so I type 'gc "chore: commit message"'
         | gd = git diff       gs = git status       gr = cd's to the top
         | level of the repo, cd - returns to your previous position.
         | 
         | I had to override some of the oh-my-zsh defaults in my .zshrc:
         | unalias gcd       unalias ga       unalias grep       unalias
         | gr       unalias gc            alias m='mise'       alias
         | fd='fd -HI'       alias gfv='git fetch --verbose'       alias
         | gs='git status'       alias gr='cd $(git rev-parse --show-
         | toplevel)'       alias ga='git fza' # depends on gitconfig
         | containing the alias "fza"       alias gc='git commit -m' #
         | depends on "unalias gc"       alias commit-types='cat
         | $HOME/.local/dotfiles/commit-types.txt'       alias ct='cat
         | $HOME/.local/dotfiles/commit-types.txt'       alias mcdd='mcd
         | $(date "+%Y-%m-%d")'       alias sp='showpath' # showpath =
         | echo $PATH | sed -e $'s/:/\\\n/g'       alias uuidgen='uuidgen
         | | tr "[:upper:]" "[:lower:]"'
         | 
         | I hope these are useful to someone at some point!
        
           | imp0cat wrote:
           | If you really want to minimize typing, try Emacs + Magit.
        
             | bloopernova wrote:
             | I should, I use Emacs a bunch, but I guess it's just muscle
             | memory now to flip to the terminal.
        
         | listeria wrote:
         | I see that you're using --print0 and -0 for your "git fza"
         | alias, it might be useful to add -z to the git-ls-files
         | invocation and --read0 to fzf.
        
           | bloopernova wrote:
           | Ah, good point, I do need to revisit these and tidy them up.
           | The perils of cargo-culting!
        
       | henshao wrote:
       | 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?
        
         | bloopernova wrote:
         | 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.
        
           | henshao wrote:
           | 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
        
             | bloopernova wrote:
             | 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 :)
        
         | nextaccountic wrote:
         | 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>.
        
           | keybored wrote:
           | 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?
        
         | mindcrime wrote:
         | _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_
        
         | n4r9 wrote:
         | 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.
        
           | kaffekaka wrote:
           | 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.
        
             | n4r9 wrote:
             | If you're willing to report back I'd be very grateful.
        
           | henshao wrote:
           | 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
        
         | ahmetsait wrote:
         | 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
        
           | n4r9 wrote:
           | 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.
        
           | henshao wrote:
           | 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...
        
       ___________________________________________________________________
       (page generated 2024-11-03 23:00 UTC)