News for hackers. Stuff that matters.
Re:Git undo: We can do better by thewebcount on Monday June 21, 2021 @12:55PM (#27581016)
I'm sorry, but how many bits of git's UI do we have to force users to manually replace before we realize that the entire problem is git's UI?

Between the tone deaf responses here about "using a GUI client is the problem," to the tone deaf responses of "you just have to learn it's internal architecture," it should be obvious what the problem is. The problem is not just being able to undo a mistake (though that's certainly one of the problems). Git is an incredibly user-hostile experience, and someone needs to fix or replace it. Can we just say it out loud and stop pretending that the problem is the literally thousands of users who have problems using it?

Re:Git undo: We can do better by rjmunro on Monday June 21, 2021 @01:44PM (#27581598)
There is no doubt that a bunch of the general commands are really poorly named, or mixed together. `git checkout branch` means switch to a branch - that's fine. But `git checkout filename` means "undo changes to the file". What? That's totally insane.

`git branch new-branch-name` means create a new branch. Great, but it doesn't check out the branch, which you want like 99.9% of the time. If you want to do that, you use `git checkout -b new-branch-name`. Yes, a third separate use for git checkout.

Why not (e.g.) `git branch -c new-branch-name` with a config option to make `-c` the default if you want it?

If you rebase and push, it tells you to do a `git pull` to "fix" it, when in every workflow I've ever done, you want to add a `-f` and push away, just be aware that you are intentionally overwriting the remote branch.

Re:Git undo: We can do better by RvdV on Monday June 21, 2021 @02:20PM (#27582036)
New commands 'git switch' (git switch -c for new branch) and ' git restore' address exactly that issue and are available on newer git versions, so it's being worked on!

I do agree with the second example. Pulling and merging with remote after a rebase makes a terrible mess!

Re:Git undo: We can do better by npteljes on Monday June 21, 2021 @01:50PM (#27581665)
And if I create a new branch locally, why must I specify what name I'd use for it on the remote? Why would I like an other name I wonder? It's fantastic that it can do this, but the default should be the branch name I'm using and that's that.
Re:Git undo: We can do better by lmm on Tuesday June 22, 2021 @05:09AM (#27589511)
> And if I create a new branch locally, why must I specify what name I'd use for it on the remote? Why would I like an other name I wonder? It's fantastic that it can do this, but the default should be the branch name I'm using and that's that.

You can fix this by doing `git config --global push.default current`.

Re:Git undo: We can do better by u801e on Tuesday June 22, 2021 @01:51AM (#27588425)
Are you referring to the git branch command? As far as I'm aware, you don't have to specify the name of the remote branch when creating a new local branch. And when you push to the remote, a branch with the same name is created by default. You would have to specify the remote branch name when running git push if you wanted a different name for the remote branch.
Re:Git undo: We can do better by npteljes on Tuesday June 22, 2021 @03:20AM (#27588894)
My env doesn't do this. Here's what I did:

    git checkout -b test
    git push
And I got "fatal: The current branch test has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin test"

But in this situation, we actually push with "git push -u origin branchname".

After deleting the "test" branch, I recreated it with "git branch test", switched to it and tried a push, and I got the same error message.

Re:Git undo: We can do better by CRConrad on Saturday June 26, 2021 @08:03AM (#27641155)
AIUI the problem there wasn't with the branch name, but that the "-origin" bit -- the reference for where to push to / pull from -- was missing. The -u parameter someone else suggested apparently sets that at the same time as pushing/pulling, so it combines the effect of "--set-upstream" suggested in the error message you got and then push/pull. (A bit like "checkout -b newbranchname" combines creating and then switching to a branch; there is some consistency to the UI, but it's weird and spotty.)

I've almost never had this problem; nearly all branches I've come across usually "know all by themselves" where their remote is. I suspect they inherit it from a global or repository-level setting that might be missing from your setup. Have you tried executing that "--set-upstream" it suggests? Maybe that sets it for the whole repo, or have you had to repeat it for each branch (like the "-u" parameter for the push seems to imply)?

Or maybe, even if you have the remote set correctly on the repo level, branches just somehow don't "inherit" that...? Idunno, maybe some magic setting missing. Aha, one further possibility: If you set the remote on the "master" (or "main") branch, maybe branches branched off from that (and others branched off from those, etc) "inherit" the remote setting?

Finally: Creating a git repo by cloning in stead of from scratch (git clone in stead of git init) automagically sets the remote for the master branch of the newly cloned repo to the master of the repo it was cloned from. Maybe, if this is how it works, that's why it's always worked for me: I've worked mainly with cloned repositories, and my branches are almost always -- albeit sometimes indirectly -- branched, ultimately, from "master".

Anyway, I think somewhere among all that there should be something that fixes your problem once and for all (i.e. for all future branches once it's correctly set for a repo). I'm sure your problem isn't standard behaviour. HTH!

Re:Git undo: We can do better by u801e on Tuesday June 22, 2021 @09:36AM (#27591427)
Have you tried running:

  git push origin HEAD
In both Github and Github Enterprise, that command will create a branch with the same name on the remote.
Re:Git undo: We can do better by npteljes on Wednesday June 23, 2021 @03:57AM (#27601970)
Works like a charm, thanks!
Re:Git undo: We can do better by cerved on Monday June 21, 2021 @02:31PM (#27582199)
Git checkout branch means change the entire working tree to the reflect the state of the branch and git checkout file, checkout the state of that file in HEAD. Both commands to the same thing, change the state of your working tree to reflect a point checked into version control.

It sounds like you are unaware of

  git switch branch
and

  git switch -c new-branch
Re:Git undo: We can do better by Vinnl on Monday June 21, 2021 @03:08PM (#27582862)
Just a tip: when teaching people, the readable alias is easier to remember and understand, i.e.

    git switch --create new-branch
Re:Git undo: We can do better by wstone on Tuesday June 22, 2021 @05:52AM (#27589723)
Thank you. It seems silly but my first parse was "-c(heckout)" but that comes from not using "switch" yet; I need to rewire my brain from "checkout".
Re:Git undo: We can do better by riquito on Monday June 21, 2021 @03:31PM (#27583233)
It was a good example: it was obvious by the name of the branch and he/she was teaching the real word use case
Re:Git undo: We can do better by ufo on Monday June 21, 2021 @06:01PM (#27585104)
By the way, I recommend using `push --force-with-lease `instead of `push --force`. This way it doesn't destroy the remote changes if someone else pushed while you weren't looking.
Re:Git undo: We can do better by mdaniel on Monday June 21, 2021 @05:07PM (#27584495)
> But `git checkout filename` means "undo changes to the file". What? That's totally insane.

Heh, and I'll do you one better: it's unstaged changes, so it won't put the file back to the HEAD version 100% of the time >:-)

Re:Git undo: We can do better by nexuist on Monday June 21, 2021 @01:10PM (#27581166)
The problem is just that collaborative text editing between multiple users simultaneously is hard. It's a human problem and git attempts to be a technical solution but the abstraction fails at the edge cases.

Regardless, what's so bad about deleting the repo and pulling from remote if you can't figure out why you hosed it? It's not like it costs you anything to do `rm ... && git clone ...`. And it's not like this happens daily either.

In the rare case that someone hoses remote, yes you'll have to do some weird git-fu to get everyone working again, but it's really hard to hose remote if you stick to the pull -> commit -> push -> merge pattern, which is what 99% of users are doing anyways. I've used git for 9 years and I've never had to spend longer than an hour troubleshooting git based BS. And if you'll remember, 9 years ago git wasn't the clear winner, it had competition via SVN and Mercurial. Both of them are practically irrelevant at this point so however bad git's UI was, it's clearly better than anything else that existed before.

Re:Git undo: We can do better by chriswarbo on Monday June 21, 2021 @01:23PM (#27581326)
> It's a human problem

If it were a human problem, how could alternatives like Mercurial and Darcs get consistent amounts of praise for their intuitive workflows?

> 9 years ago git wasn't the clear winner, it had competition via SVN and Mercurial. Both of them are practically irrelevant at this point so however bad git's UI was, it's clearly better than anything else that existed before.

SVN isn't distributed; it mostly tried to replace CVS, which it managed to do very successfully.

As for DVCS, the fact that system X became more popular than system Y doesn't mean that every aspect of X is better than Y. Many would say git succeeded despite its awful interface. As far as I can tell, the main feature of git was its speed; that made it usable for huge projects like Linux and Xorg, and this endorsement from high-profile projects gave git the edge for DVCS hosting sites like Gitorious. Then GitHub came along, and grew into such a behemoth that git became the de facto standard.

See also: WorseIsBetter

Re:Git undo: We can do better by umvi on Monday June 21, 2021 @01:34PM (#27581463)
> If it were a human problem, how could alternatives like Mercurial and Darcs get consistent amounts of praise for their intuitive workflows?

Because maybe mercurial's real problems wouldn't show up until people started using it at scale.

This is a classic problem that happens time and again.

Windows vs. Mac back in 2005:

"Windows having malware is a human problem"

"If it were a human problem, how could alternatives like Mac get consistent amounts of praise for their lack of malware?"

Turns out it's just because Mac didn't have a big enough market share. As soon as it did, Apple could no longer claim that Macs can't get malware because they can and do.

Similarly, if you scaled up the number of Mercurial users by several orders of magnitude so that it was now "mainstream", I'm sure some of its lesser known pain points and/or counter intuitive behaviors would start floating up to the top 10 HN stories. But since hardly anyone uses Mercurial vs. Git, that doesn't happen. Just because a minority of users praise something (<insert lesser known language>, <insert lesser known DB>, <insert lesser known VCS>, etc.) doesn't mean if you scaled up the userbase one or more magnitudes it would continue getting that level of praise from all users.

Re:Git undo: We can do better by Izkata on Monday June 21, 2021 @01:54PM (#27581706)
> Because maybe mercurial's real problems wouldn't show up until people started using it at scale.

I actually tried both git and mercurial almost a decade ago having had only experience with subversion, and found git to be much easier to understand and use. I don't recall what those pain points were, and am sure I couldn't describe them correctly if I did remember, but because of that I do expect such things to start popping up if more people used it.

Re:Git undo: We can do better by pseudalopex on Monday June 21, 2021 @08:26PM (#27586408)
Mercurial scaled better actually. It's 1 of the reasons Sun, Mozilla, and Facebook used it instead of Git.

Typically Git was a bit faster for most operations on Linux. Mercurial was a bit faster for other operations. Especially on Windows. And both were much faster than the rest.

Bitbucket and GitHub started around the same time. GitHub just executed better.

Re:Git undo: We can do better by daxelrod on Monday June 21, 2021 @01:24PM (#27581346)
I agree that collaborative text editing between multiple users simultaneously is hard.

That doesn't mean that Git couldn't have a much better UI for this problem than it does. And while I agree that Git seems to have mostly won over SVN and Hg, it doesn't follow that it's because of its UI. (For example, I think that a lot of Git's success actually comes from the UI of GitHub, not Git itself, but I don't have evidence to back it up.)

Take a look at the Research section at the bottom of https://gitless.com/ for work that's been done on how to accomplish the same operations with a simpler conceptual model.

Re:Git undo: We can do better by lanstin on Monday June 21, 2021 @02:34PM (#27582250)
This is the real interesting problem. Even simple subtle decisions like "should this list be kept sorted, or have new things added to the end" determine under what conditions you will hit a new conflict and when you won't. List of enums, add to the end, and if 2 branches grab the next enum value then you'll see a conflict. List of lets say URL prefixes keep in order, then most randomly added URL prefixes will not collide or conflict, only conflicting if you get 2 things trying to operate on the same prefix.
Re:Git undo: We can do better by FractalHQ on Monday June 21, 2021 @03:44PM (#27583421)
Wow. Reading the home page of gitless made me both excited to use it and angry at how poorly designed git’s UI and UX are. Thanks for sharing this!
Re:Git undo: We can do better by vxNsr on Monday June 21, 2021 @01:35PM (#27581480)
GitHub is what made git so popular, git wasn’t inevitable, and GitHub didn’t become huge because of git, GitHub’s big innovation was attaching a social network to a software/code repo. It’s what made it way more popular than basically all the competition, which were just software/code repos but didn’t have a great network/social story. (Also at the time GitHub was coming out, the biggest player in the space decided to monetize in an annoying way.)
Re:Git undo: We can do better by cellularmitosis on Tuesday June 22, 2021 @02:00AM (#27588467)
> Regardless, what's so bad about deleting the repo and pulling from remote if you can't figure out why you hosed it? It's not like it costs you anything to do `rm ... && git clone ...`. And it's not like this happens daily either.

Well, actually, a lot of people work in large repos, so this can be a pain.

Which of course brings up another failing of the git UI: the difficulty of removing old history from the repo. Last I checked, you pretty much have to use a 3rd party tool for this.

Re:Git undo: We can do better by quickthrower2 on Monday June 21, 2021 @01:11PM (#27581181)
I feel that I only understand git because I’m forced to use it for years, but the experience could have been a lot less painful. I use a GUI for sure. Do people really diff and resolve big conflicts at a command line? I never figured out how.
Re:Git undo: We can do better by rjmunro on Monday June 21, 2021 @01:49PM (#27581650)
Just delete the bits you don't want and `git add`

It helps a lot to set:

git config --global merge.conflictstyle diff3

then you can see the before as well as the 2 changes you are trying to resolve.

Re:Git undo: We can do better by cerved on Monday June 21, 2021 @02:32PM (#27582226)

  git mergetool
or

  git checkout --ours/theirs && git add .
Re:Git undo: We can do better by gumby on Monday June 21, 2021 @05:17PM (#27584628)
> tone deaf responses of "you just have to learn it's internal architecture,"

Why is this tone deaf? It’s a development tool for programmers and the internal structure is conceptionally pretty straightforward. Understanding your tools is pretty much prerequisite. You don’t have to have written a compiler to use one, but you do have to have a model of what it does. Git is no different.

Re:Git undo: We can do better by TobTobXX on Monday June 21, 2021 @02:32PM (#27582227)
Admittedly I did spend like a combined hour troubleshooting git over the last two months.

But git saved me an immeasurable amount of hours in return. I was asked what I worked on some specific week back in may -- git saved me. I had to look up what performance my program had before a specific change -- git saved me. I had to try stuff out without messing up my codebase -- git saved me.

True, I invested quite a few hours and I still do, but I think the investment pays itself off. I'll never ever do a project without git.

Re:Git undo: We can do better by sloucher on Monday June 21, 2021 @01:04PM (#27581096)
Last time I checked, 5 of the top 10 questions on StackOverflow were about Git...
Re:Git undo: We can do better by adamrezich on Monday June 21, 2021 @01:13PM (#27581205)
still true! but that isn't a great metric necessarily, as #10 is "What is the “-->” operator in C/C++?" https://stackoverflow.com/questions/1642028/what-is-the-oper... which is just a novelty rather than a common question
Re:Git undo: We can do better by greenshackle2 on Monday June 21, 2021 @02:49PM (#27582535)
Maybe because like 90% of devs use git; there's no language or framework that is used by so many.
Re:Git undo: We can do better by lawn on Monday June 21, 2021 @04:02PM (#27583646)
This is the one thing I took with me from The Design of Everyday Things: usability design matters, and it matters a lot.
Re:Git undo: We can do better by junon on Tuesday June 22, 2021 @02:54AM (#27588759)
> Git is an incredibly user-hostile experience, and someone needs to fix or replace it.

* in your opinion.