News for hackers. Stuff that matters.
Re:Git is too hard by secondcoming on Tuesday November 17, 2020 @06:19AM (#25122436)
+1

These commands will get you 99% of the way:

- git status

- git branch

- git pull

- git add

- git commit

- git diff

- git merge

- git push

- git checkout

For everything else there's StackOverflow, but the info in there comes with the risk of being stale.

--------------

Edit commit abaeb3b4: Add missing commands and improve formatting

Edit commit 842babda: Add git checkout

Re:Git is too hard by h0l0cube on Tuesday November 17, 2020 @06:26AM (#25122477)
`git status` is required to determine which untracked files you need to add. And then, of course, `git add` would be need to be added to the list too. To add untracked files you could use interactive mode `git add -i` and forgo reading `status`. But you can also `git commit -p` if you only modified files and forgo the `add` step.

And to give yourself a sense of the commit graph, these aliases come in handy

    [alias]
        lol = log --graph --decorate --pretty=oneline --abbrev-commit
        lola = log --graph --date=short --pretty=format:'%C(auto)%h %C(dim)%ad%C(auto)%d %s' --all
The only 'advanced' thing I commonly do is `git rebase -i` to squash a bunch of WIP commits. And a shell script I have to turn merged branch into a tag, and remove the branch.

The other day I had to remove a sensitive file that accidentally got checked into the repo for a couple of commits behind HEAD, and was glad that git had the power to do this in one line and without fuss. (Edit: but yes, I had to look it up on SE)

Re:Git is too hard by secondcoming on Tuesday November 17, 2020 @06:49AM (#25122650)
Indeed, I forgot 'git status', and 'git add'

I've honestly ever felt the need, or had the requirement, to look at the graph.

Re:Git is too hard by h0l0cube on Tuesday November 17, 2020 @07:04AM (#25122770)
I've found it indispensable when tracking and integrating other peoples' branches. I wouldn't use it so much if I was working solo.
Re:Git is too hard by sethammons on Tuesday November 17, 2020 @07:44AM (#25123078)
I've never worked solo. My teams tend to be around 6-8. Across a dozen teams, myself and nobody on the team save a couple even looked at the graph. One who loved a clean history showed it off, people thought it was pretty, and went back to work as normal. `git commit -am 'slightly helpful message' && git push origin $branch` does about 90%+ of what I've needed. When we merge the branch, squash merge works fine. History graphs, I've never felt the need for them.
Re:Git is too hard by h0l0cube on Tuesday November 17, 2020 @04:27PM (#25130111)
Each to their own. I use it in situations where i want to know what other people are basing their branch from. Which, for projects I've worked on, can have real consequences. For instance, it may prompt me to rebase upon their work sooner, or even give them a heads up that theirs some useful change I'm submitting to the trunk.
Re:Git is too hard by sethammons on Tuesday November 17, 2020 @05:13PM (#25130638)
ah, that is likely part of it. We always branch from master and merge back to master. Builds prevent failing code from merging. It is rare that we branch from a branch, and that 2nd branch would never be merged before the first.
Re:Git is too hard by h0l0cube on Tuesday November 17, 2020 @05:31PM (#25130809)
During rapid mobile and frontend development, occasionally I'll be working on someone where there's co-depending feature branches, but for the most part the team usually follow something like git-flow. But I take your point that viewing the graph isn't essential, and those aliases might look scary on a one-page crash course. (I really think `git lol` and `git lola` should be first class citizens of a git installation though)
Re:Git is too hard by secondcoming on Tuesday November 17, 2020 @08:37AM (#25123550)
We're the exact same except for the squashed merge (which I have no real objection to doing)
Re:Git is too hard by nicoburns on Tuesday November 17, 2020 @06:57AM (#25122703)
I think `git checkout` definitely needs to be there. Also `git reset` in case you make a mistake while `git add`ing
Re:Git is too hard by samhh on Tuesday November 17, 2020 @07:04AM (#25122762)
I think the most common usage of that - switching branches - could be replaced with `git switch` now. That leaves `git checkout` in the set of more advanced operations for more niche use cases.

Same goes I think for `git restore` over `git reset`.

Re:Git is too hard by secondcoming on Tuesday November 17, 2020 @07:10AM (#25122817)
Added checkout. I'm not sure about classifying 'git reset' as an 'everyday' command.
Re:Git is too hard by kubanczyk on Tuesday November 17, 2020 @06:04PM (#25131116)
Correct. The use case falls under `git status` really, it will give you boilerplate commands like `git add`, `git reset`, `git checkout -- file`, or even `git rebase --abort` depending on a situation.
Re:Git is too hard by jariel on Tuesday November 17, 2020 @06:36AM (#25122549)
So this, to me, is not a 'benefit of git' it articulates in some ways how bad it is (although very powerful).

Most people can get going with those 99% commands quite quickly, the problem with git is any move from the known path creates some pretty amazingly complicated scenarios.

And those '1% of the time' commands blow up into time-consuming rabbit holes of complexity. Often, Stack Exchange has several answers for the same question, highlighting just how much inherent complexity there is in the product.

Managing software versions across repo can be a very, very complicated problem. Git provides you with a pile of tools to do 'almost anything'.

A 'well designed product' would make the toolsets and concepts focus heavily on the 'main operations' and then have clear, clean rational idioms, practices and tools for the odd cases, and 'dangerous cases' wouldn't be allowed without some kind of special command.

They have the 'Golden Rule of Git' which is to not rebase on a public branch - this is an excellent example of poor product design. There should be no 'golden rule' that developers have to understand - it shouldn't be possible (without special admin commands). If branches are named/tagged and managed properly, the system would be smart enough to let you know you can't do that, and why.

Administrators exist for a reason, 'sudo' exists for a reason etc.

People who love powerful things, and have an inclination towards complexity seem to love git, people who have a product orientation see it differently.

Re:Git is too hard by jamienicol on Tuesday November 17, 2020 @07:00AM (#25122738)
You can't push a rebased branch without`--force`, and the server can be configured to disallow it entirely. This is exactly how it should be: I want to be able to rebase my by public branches but not the public branch.
Re:Git is too hard by jariel on Tuesday November 17, 2020 @10:28AM (#25124835)
" I want to be able to rebase my by public branches but not the public branch."

Already that's a little bit complicated though.

Even though yes, this use case probably does exist, it might be a tricky thing to unwind for some people - what would they do when they have already changed the history of 'their' public branch (?) is something they'd have to carefully think about.

Re:Git is too hard by lttlrck on Tuesday November 17, 2020 @08:40AM (#25123578)
Stack exchange has multiple answers for most questions. It's not a useful metric; the domain is inherently complex. git has warts, like c++, go, react, npm, rust and all their cousins.

It comes with the territory. We're dealing with tools borne into world where they are, more and more, expected to be suitable for any purpose. Tough mandate, and not the tools fault.

One day git will be supplanted with something that has a different set of issues. Progress.

Re:Git is too hard by aulin on Tuesday November 17, 2020 @07:29AM (#25122969)
you shouldn't change history once you make it public, how hard is that? that's the golden rule, if you promise something to be immutable, stick to your promise
Re:Git is too hard by outsomnia on Tuesday November 17, 2020 @08:22AM (#25123418)
Tags are immutable. Branches are mutable.

You can add to them and refactor patch series that are on them, equally valid in the eyes of git.

For example a development branch has no implied "promise" about stability of its history, it is much better to not only refactor the code but also refactor the history so sub-patches are squashed into the single feature patch that they logically belong to, and not spawn lives of their own. There is no reason to run that kind of development branch like a stable "branch of record".

Re:Git is too hard by jariel on Tuesday November 17, 2020 @09:11AM (#25123899)
'Don't shoot yourself in the foot with a gun - how hard can that be to understand'?

And yet people do it all the time.

The 'rule' is easy enough to understand.

But it's not always clear 'why' that is (in many cases, it won't matter), or when exactly it applies.

In the lowest common denominator cases, the rule is not so hard to follow, but it can get messy quickly and there are many ways to break the rule.

Re:Git is too hard by pelasaco on Tuesday November 17, 2020 @06:45AM (#25122618)
I use git daily. I never use merge. I use git rebase, and its interactive version all day.
Re:Git is too hard by samhh on Tuesday November 17, 2020 @07:05AM (#25122773)
You'll potentially need to use merge if you're collaborating with others on feature branches.
Re:Git is too hard by secondcoming on Tuesday November 17, 2020 @07:11AM (#25122822)
Ya, I'm the opposite, I never use rebase. Horses for courses...
Re:Git is too hard by aeyes on Tuesday November 17, 2020 @08:34AM (#25123526)
You should, or do you just merge updated remote branches into your stale local branches? A lot of new developers seem to do that here until we explain to them how it messes up the history.
Re:Git is too hard by Supermancho on Tuesday November 17, 2020 @09:02AM (#25123802)
> do you just merge updated remote branches into your stale local branches?

Every single developer I work with (or have in the last 8 years) does this. "Messes up the history" ? The merge commit describes that there are uptaken changes from the "main" branch. It doesn't seem to be a problem in practice.

Re:Git is too hard by KptMarchewa on Tuesday November 17, 2020 @09:44AM (#25124244)
It's also not a problem for me, because I squash the commits on merge to master or other remote branch.
Re:Git is too hard by secondcoming on Tuesday November 17, 2020 @01:31PM (#25127603)
We don't merge one-off branches into other one-off branches unless they're all under the same feature. Everything goes via develop when they're complete, and new one-off branches are created from develop.

When we release to production, develop gets merged to master.

We consider a 'feature' a large piece of work that will take several weeks, during which time several releases to production may be done for other work/tickets.

Re:Git is too hard by recursive on Tuesday November 17, 2020 @09:44AM (#25124250)
I've been doing that for years, and it's never messed up the history.
Re:Git is too hard by fphilipe on Tuesday November 17, 2020 @07:38AM (#25123037)
I use git-show a lot to look at individual commits. Would add that to the list.
Re:Git is too hard by outsomnia on Tuesday November 17, 2020 @07:52AM (#25123132)
fetch is also a primitive