Hacker News new | past | comments | ask | show | jobs | submit login
How I use git (thorstenball.com)
41 points by signa11 3 months ago | hide | past | favorite | 21 comments



As someone who is no longer a professional programmer and does not work on a team, how I use git is I have an alias called `yolo` that adds everything, commits with allow-empty-message, and pushes it all to main, where it is immediately deployed without gates straight into production. I've gone feral, and I'll never be an inside cat again.


Good luck going back to that repo in a few months :)


The most likely alternative to "yolo" is no change control. They've got the most important part, the history.


But that history is hardly useful without metadata to tell them what each snapshot contains, at the very least. The only thing they have to go by is the commit date, so they can never know whether a snapshot is stable, what to revert to, etc. At that point you're not much better off from doing manual versioning by compressing the directory, and naming each file `v1`, `v2`, `v3-final-final2`, etc. (: They don't need Git for that.


The thing is, I don't really work on a complicated app anymore, and I'm the only one who commits to it. So, there's not much to think about. I know that if it worked last Wednesday and is broken now, I should roll it back to last Wednesday, etc.


Lots of people commented on the comment about not needing a GUI client in this thread (same link): https://news.ycombinator.com/item?id=41890480

To add my own touch, I find staging certain parts of a file in the CLI bothersome, when I can just click-and-drag highlight what lines I want committed in eg. Sublime Merge. Not perfect, but waaay easier than with the default CLI in my opinion.


Something I've always wanted is a simple way to rearrange local commits between different branches (or reorder them) by clicking and dragging. I know there are CLI tools out there to do it, but I haven't explored the options yet. I think that's much more intuitive than doing the same actions using the CLI, although that's mostly because using the CLI forces you to know the Git internals by heart, which is probably a good thing in the long run.


https://github.com/jesseduffield/lazygit

Can do it with a couple keys, 4 (commits tab), then ctl+j/k depending on where you want the commit to be.


I think for folks looking to basically do a "click-and-drag rebase" like that, a GUI interface with comparable ease in displaying and resolving patch application issues (diffs that don't apply) is hard to come by.

I've heard good things about gitkraken though, but haven't used it myself.


For me, I actually started off Sourcetree and my knowledge of git commands actually comes from their “show console output” option.


Hard agree. My gripe with git gui is that they facade complex operations behind simple user actions and can land users in no man's land mid operation.

Visual staging is extremely useful though and is a simple, single action.


I find 95% people should use decent GUI. That 5% I have never worked with.

Also 40% of devs it is a badge of honor “not using GUI” and fool themselves they understand what is going on.

Numbers based on my mood today and S&P500 performance last week - don’t take it personally but maybe take into account it might be useful to see those branches in GUI, maybe it is useful to have diff tool where you can click around, take time to understand the context of the team setting and what others were just doing and what is going to prod soon.


Git is meant to be distributed . I encourage using git clones locally for deployments and archiving . git push via ssh to deploy to a machine , rather than complicated CI . Git push configuration from your home dir to etc on the same machine .

Another tip is to constantly use the reflog. Reflog is your history of the history. Even if you lose a branch or commit garbage with a forced commit , reflog will restore it. That is very powerful. Just commit and experiment and reflog to undo

Git comfortable with the decentralized and wild nature of git .


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
  ws = !git show --word-diff=color --word-diff-regex='\\w+'
  wd = !git diff --word-diff=color --word-diff-regex='\\w+'
  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.

"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.

Edited to add:

"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.

I never use "git ws" and "git wd", I should remove those.


As someone who also uses Git exclusively from the command line, without any TUI wrappers, I agree with a lot of this. The parts about commits being revertable, bisectable and in general _atomic_ are very important, and IME the only correct way of using version control.

One exception: conventional commits. I find them very useful even on solo projects, since a) they make it easy to spot the type of change at a glance, and b) they force me to keep commits atomic. That is, if I'm ever compelled to make a commit that is both a `fix` and a `refactor`, usually out of laziness :), sticking to a conventional commit message is a quick way to determine what needs to be split into a different commit. These conventions really shine when used in a team, as they improve communication and keep the history tidy (along with all other benefits of atomic commits), but so far I haven't had the luck to work on teams that agree to adopt them. Using these commits to generate changelogs would be wrong, as changelogs should almost never be autogenerated (though these days maybe AI does an acceptable job at it), but they're still useful to keep track of the number of fixes, features, etc. that were produced in a release.

And a tip: in addition to plain shell and Git aliases, I've found scmpuff[1] and delta[2] to be invaluable in a Git CLI workflow.

[1]: https://mroth.github.io/scmpuff/

[2]: https://github.com/dandavison/delta


Here's how I use git:

1. git status doesn't need to be run manually, https://github.com/woefe/git-prompt.zsh

2. I dislike aliases because they only work locally and not anywhere else which will be just confusing and especially when confusing when dealing with an emergency on non-local. It also makes sharing workflows harder. So I'd rather not use any.

3. On the other hand, I override git reset to commit before destroying work to save my own bacon. Oh and I added git cd which I guess contradicts #2 but oh well :) -- it's also not an alias -- and, to be fair, I use it somewhat rarely and it's not really a git command -- I could've named it cd-git-relative or something. Anyways here it is: https://gist.github.com/chx/d4e30aaf8e3d9a6fccad9e89bb8d73b8


How much of your work happens locally? For me, it's probably 99.9%, everything else is temporary shells in Kubernetes pods. For the 0.1% cases, I'm fine with consulting .gitconfig (or zsh plugin) for what the alias does, if I happen to even need it.


I came to suggest (once again) lazygit.

https://github.com/jesseduffield/lazygit

Love the ability to pull a hunk out of a commit, create a new commit, then throw it over to another branch, with the press of a few keys.


We use git exclusively at work. This experience taught me to love fossil which I use exclusively at home. It is simple and has all the associated programs apart from the rcs part built in. I do not miss the git foot guns.


I'm curious if anyone working in smaller teams (say, <6 devs) has found it worthwhile to try to standardize some of the git process. Larger teams I've worked in have tended to have some standards we're following - but the times I've worked on smaller teams it's tended to be

I think if I were starting a team for scratch it's likely something I'd establish from the beginning - commit message guidelines, PR requirements, squash/rebase/merge standards. But I've only ever come into teams that have been working on the product for at least a year - and it's never seemed worth the 'political capital' to wrangle the team into a new standard for it.

I've tended to opt for doing things the way I think is right given that we aren't following a standard anyways - and pointing to the benefits of it when they come up.


Our team is small and we use:

  git hooks from https://pre-commit.com
    git-conventional-commits to enforce standardized messages
    linting
  github branch protection rules
  CODEOWNERS file and PR templates to speed PR creation
One issue we still have is that in this particular organization, different teams have different standards, and we have to deal with those differences which causes annoyance but not really much more.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: