Live data from Hacker News

Ask HN: What is your Git commit/push flow?

news.ycombinator.com

131–140 of 201 posts

Re: Ask HN: What is your Git commit/push flow?

#131
post #9

Here's how I address this problem. When I'm developing, but before I create a PR, I'll create a bunch of stream-of-consciousness commits. This is stuff like "Fix typo" or "Minor formatting changes" mixed in with actual functional changes. Right before I create the PR, or push up a shared branch, I do an interactive rebase (git rebase -i). This allows me to organize my commits. I can squash commits, amend commits, mov…

The only problem I have with this workflow in the command line is that I would like to be able to split changes to the same file across multiple commits. I think some GUI tools enable this, anyone know about it?

If you have a Mac, check out GitUp. It's a simple but fantastic tool for cleaning up git histories: merging commits, splitting commits, reordering...

Re: Ask HN: What is your Git commit/push flow?

#132
post #9

Here's how I address this problem. When I'm developing, but before I create a PR, I'll create a bunch of stream-of-consciousness commits. This is stuff like "Fix typo" or "Minor formatting changes" mixed in with actual functional changes. Right before I create the PR, or push up a shared branch, I do an interactive rebase (git rebase -i). This allows me to organize my commits. I can squash commits, amend commits, mov…

This is very close to my approach. I work in a private branch and make many commits along the way, but then organize it to tell a coherent story for the actual PR.

Re: Ask HN: What is your Git commit/push flow?

#133
I like to

  git commit --amend --no-edit
often

once a piece of functionality is working, edit the commit so it makes sense

start new commit and work on next piece of functionality, repeat

clean commit history not just for me but for my coworkers who will benefit from seeing a cohesive commit diff

Re: Ask HN: What is your Git commit/push flow?

#136

I like to git commit --amend --no-edit often once a piece of functionality is working, edit the commit so it makes sense start new commit and work on next piece of functionality, repeat clean commit history not just for me but for my coworkers who will benefit from seeing a cohesive commit diff

I imagine many like me use it so often they have this as the alias “git oops”.

Re: Ask HN: What is your Git commit/push flow?

#137

Earlier quoted context omitted.

The only problem I have with this workflow in the command line is that I would like to be able to split changes to the same file across multiple commits. I think some GUI tools enable this, anyone know about it?

I use the interactive flag on git add for this. It lets you add parts of a file, commit, and then do it all again. I want to say it's git add -i, but I'm not 100% on that. My fingers just do the right thing when I want it to happen.

It's "p" for "partial"

Re: Ask HN: What is your Git commit/push flow?

#138

>I also push often because I'm forever aware disks can fail. In the 20+ years that I've been using computers, and ≈15 or so that I've been writing software, I've never experienced a drive failure.

Some non physical failure scenarios I have experienced include catastrophic filesystem failures (NTFS: never again), loss of machine and no handy backup machine capable of reading the disk or filesystem in question (extX, ZFS, etc.), accidental damage to disk, partition or filesystem tree due to bad code (operator error; PEBSAC).

Re: Ask HN: What is your Git commit/push flow?

#140
I barely skimmed what's below so maybe someone else has covered this, maybe not.

If I need to hack on a task and I know I'm the only person that's going to work on the branch I amend changes to my commit basically constantly. The only reason I might not is if I want multiple commits on the branch to make review simpler for others.

```

git fetch && git checkout main

git branch feature/JIRA-###/words-describing-it

git checkout feature/JIRA-###/words-describing-it

git add .

git commit -m "JIRA-###: words / description"

git push -u origin feature/JIRA-###/words- describing-it

git add .

git amend

git push -f

```

`git amend` is an alias in my ~/.gitconfig

```

#cat ~/.gitconfig

[alias]

        amend = commit --amend --no-edit
```

So most of my commits I just amend the first commit I made, force push, review CI build results, rinse repeat until it's ready for review.

Simplest thing that works when it's just my own work on a branch. I'll also do a rebase pre PR review if need be.

```

git fetch && git rebase -i origin/main

git status

git add

git rebase --continue

git push -f

```

Post reply on HN