News for hackers. Stuff that matters.
Re:Git Commands You Probably Do Not Need by kramerger on Monday January 23, 2023 @06:46AM (#34487731)
Git commands you do need:

    git init
    git clone

    git add
    git rm

    git commit
    git push
    git pull

    git branch
    git checkout

If you use any others and you are a normal developer, chances are you are overcomplicating things and should rethink your way of using git.

But how about logs you may ask. Well, that's what we have tig for:

    sudo apt install tig
    cd repo
    tig
Re:Git Commands You Probably Do Not Need by nicoburns on Monday January 23, 2023 @07:09AM (#34487895)
You're missing:

    git status
    git log
    git reflog
    
    git reset

    git merge
    git cherry-pick
    git rebase
These days you can use the new (and less confusing) "git switch" and "git restore" commands instead of "git checkout". I still use "checkout" because it's ingrained in my muscle memory. But I wouldn't recommend it for new developers.
Re:Git Commands You Probably Do Not Need by Shacklz on Monday January 23, 2023 @07:00AM (#34487832)
> If you use any others and you are a normal developer, chances are you are overcomplicating things and should rethink your way of using git.

I strongly disagree with this one.

Git is one of those constants in our developer-live that is bound to stay for a long time. Probably longer than most other tech/tool that most of us use and learn on a daily basis.

The fundamentals of git aren't that complicated, the datamodel isn't any more complex than what you get taught in an introductory datastructure course. And once you understood it, you can leverage it to create an actually readable and usable commit history instead of the unreadable mess that your average enterprise project is. In my opinion, it's well-worth the trouble of taking an afternoon to understand git beyond the commands you've mentioned.

Re:Git Commands You Probably Do Not Need by kramerger on Monday January 23, 2023 @07:06AM (#34487866)
> The fundamentals of git aren't that complicated,

Agreed

> the datamodel isn't any more complex than what you get taught in an introductory datastructure course.

Also true. The problem is that people love to shoot themselves in the foot by overcomplicating normal use of git That's all fine, until you try to push to someone else's repo and things start to crack.

So as a person who had to maintain a fairly large project, and had to fix a lot of madness from developers I nowadays suggest everyone keep their git adventures to a minimum.

Re:Git Commands You Probably Do Not Need by searchableguy on Monday January 23, 2023 @06:51AM (#34487767)
I will add pull, fetch, prune, config, merge, remote, cherry-pick, reflog, rebase, reset, bisect, stash, etc to that.
Re:Git Commands You Probably Do Not Need by darrenf on Monday January 23, 2023 @06:58AM (#34487814)
I'll add `clone` and `annotate` too.
Re:Git Commands You Probably Do Not Need by kramerger on Monday January 23, 2023 @06:59AM (#34487827)
Ah, forgot clone :)
Re:Git Commands You Probably Do Not Need by bombolo on Monday January 23, 2023 @07:02AM (#34487852)
git tag
Re:Git Commands You Probably Do Not Need by 5e92cb50239222b on Monday January 23, 2023 @06:54AM (#34487788)
… which results in either losing work sooner or later (because you don't commit often and early enough to always have something to roll back to), or pollutes history with junk WIP commits and merges. Maybe this is because I am not a "normal developer" (more like below normal), but this "overcomplication" both produces a clean and easy to read history (that is also easy to bisect when anything goes wrong and you need to find the offending commit), and also saved my bacon countless times.
Re:Git Commands You Probably Do Not Need by ilyt on Monday January 23, 2023 @07:06AM (#34487876)
> … which results in either losing work sooner or later (because you don't commit often and early enough to always have something to roll back to),

You can just git add without commit. The changes will be saved to index and live till git decides to GC its files (so few months). Extracting those might be PITA (as requires playing with more arcane git commands) but you can't really lose data

git stash is also lifesaver if you need to quickly jump to branch to do something else

Lastly there is "git commit --amend" way of just incrementally changing the current commit but that requires some self-discipline (or hooks preventing your from) to not amend pushed commit and then having to fix that.

Re:Git Commands You Probably Do Not Need by forgotpwd16 on Monday January 23, 2023 @07:20AM (#34487966)
Worth noting that `git switch` and `git restore` have been introduced (few years now) as easier-to-use alternatives to `git checkout`. Even in status you can see it's restore that is shown in the help messages. From commands mentioned, it's missing (one of) my most often used one(s) `git diff`. What's the point of using a version control if to never check what changes are made?
Re:Git Commands You Probably Do Not Need by marssaxman on Monday January 23, 2023 @09:40AM (#34489262)
I recently retrained myself to use 'switch' and 'restore', and a perceptible fraction of my lingering loathing for git's incoherent UI has now faded.
Re:Git Commands You Probably Do Not Need by 0xCAP on Monday January 23, 2023 @06:53AM (#34487781)
So basically no fetch, pull or rebase? Mmh...
Re:Git Commands You Probably Do Not Need by Forge36 on Monday January 23, 2023 @06:47AM (#34487742)
Thoughts on rebase?
Re:Git Commands You Probably Do Not Need by kramerger on Monday January 23, 2023 @06:57AM (#34487811)
Maybe,

... although these days rebase is mostly handled on the server. By the time your PR is reviewed its already behind main so server side needs to rebase it anyway before merge can be done.

If you do rebase to squash commits, most projects prefer you didn't

Re:Git Commands You Probably Do Not Need by nicoburns on Monday January 23, 2023 @07:02AM (#34487850)
> If you do rebase to squash commits, most projects prefer you didn't

I've been using rebase to fix bugs in earlier commits (on a feature brannch that hasn't yet been merged into main) so that you don't end up with broken commits in the history.

I've also been using filter-branch to retroactively apply autoformatting to all commits in the branch.

Re:Git Commands You Probably Do Not Need by xmcqdpt2 on Monday January 23, 2023 @07:49AM (#34488163)
You should rebase instead of merging when pulling though otherwise you contaminate your branch with merges that mess up the git log.

Alternatively you can squash the merges before pushing but this still requires rebasing.

Re:Git Commands You Probably Do Not Need by throwaway525142 on Monday January 23, 2023 @06:52AM (#34487776)
`git remote`?
Re:Git Commands You Probably Do Not Need by zirgs on Monday January 23, 2023 @06:51AM (#34487761)
You forgot `git submodule`
Re:Git Commands You Probably Do Not Need by coffeeblack on Monday January 23, 2023 @07:18AM (#34487946)
That’s the one part of git that I dislike.
Re:Git Commands You Probably Do Not Need by bombolo on Monday January 23, 2023 @07:01AM (#34487840)
Noooooooooooo!
Re:Git Commands You Probably Do Not Need by mst on Monday January 23, 2023 @12:23PM (#34491890)
Re:Git Commands You Probably Do Not Need by argulane on Tuesday January 24, 2023 @01:59AM (#34500355)
git-subrepo is a lot nicer to use than submodules.
Re:Git Commands You Probably Do Not Need by bombolo on Monday January 23, 2023 @07:02AM (#34487844)
> If you use any others and you are a normal developer, chances are you are overcomplicating things and should rethink your way of using git.

Or perhaps I bothered to read the documentation and I know more than you.

Re:Git Commands You Probably Do Not Need by ilyt on Monday January 23, 2023 @07:08AM (#34487890)
From my experience the circles of "complains about git" and "read the manual properly" barely touch

But that list of commands isn't really far off for daily/weekly use, I'd only use stash and rebase over that most of the time

Re:Git Commands You Probably Do Not Need by coldpie on Monday January 23, 2023 @09:34AM (#34489191)
> om my experience the circles of "complains about git" and "read the manual properly" barely touch

Yuuup. For anyone reading this who thinks of Git as a bunch of magic commands, go read all of gittutorial, gittutorial-2 and gitcore-tutorial. That last one is particularly important to read & follow along with. It gives you Git's underlying data model, which makes it much easier to reason about what the UI-level commands are doing.

I even used that knowledge once to recover my boss's lost data at a previous job! He had git-added a new file, and then lost it (git-clean/git-reset/something) before committing. I knew from reading that tutorial that git-add is sufficient to add it to git's object store, so we managed to find the right object using file timestamps and git-cat-file to retrieve it.

https://git-scm.com/docs/gittutorial

https://git-scm.com/docs/gittutorial-2

https://git-scm.com/docs/gitcore-tutorial

Re:Git Commands You Probably Do Not Need by ilyt on Monday January 23, 2023 @07:02AM (#34487843)
no git stash ?
Re:Git Commands You Probably Do Not Need by forgotpwd16 on Monday January 23, 2023 @07:41AM (#34488122)
* * *
Re:Git Commands You Probably Do Not Need by ilyt on Monday January 23, 2023 @05:58PM (#34496315)
I mean I can configure my shell correctly so that isn't a problem in the first place

    -> ᛯ date >> asd     
    [23:57:10] ^ [/tmp/a] {master *}
    -> ᛯ git stash       
    Saved working directory and index state WIP on master: bf5a0f8 fix
    [23:57:13] ^ [/tmp/a] {master $}
    -> ᛯ git pop         
    On branch master
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
     modified:   asd
    
    no changes added to commit (use "git add" and/or "git commit -a")
    Dropped refs/stash@{0} (4f46bc00a3d6032c2726f04540a44656090e05ca)
    [23:57:16] ^ [/tmp/a] {master *}
    -> ᛯ 
it's pretty non-missable (git pop is just alias to stash pop)
Re:Git Commands You Probably Do Not Need by RichardCA on Monday January 23, 2023 @05:13PM (#34495863)
If your work-in-progress files are trivial, it's easy to create a temp directory with a .gitignore with just a '*' in it and leave your files there.

If it's not so trivial, create a local temp branch so you can cherry-pick it or merge it back in later, or maybe convert your temp branch into a more enduring one.

Stashes are pseudo-commits with no branch context, and are more of a conceptual burden then they're worth.

Re:Git Commands You Probably Do Not Need by ilyt on Monday January 23, 2023 @06:06PM (#34496395)
or just type git stash

do whatever you need

git stash pop

done

> Stashes are pseudo-commits with no branch context, and are more of a conceptual burden then they're worth.

They are literally just commits like everything else. They just land in refs/stash, where branches/tags live.

Man the shit people say about how git works while not knowing how git works...

It's essentially a temporary branch with some syntactic sugar to manage

You can even just convert it to normal branch

    git branch cake stash@{0}
Re:Git Commands You Probably Do Not Need by RichardCA on Monday January 23, 2023 @06:36PM (#34496719)
Dude, have you ever tried the .gitignore trick? It really does come in handy.

And your overall tone was uncalled-for. Cheers.

Re:Git Commands You Probably Do Not Need by xmcqdpt2 on Monday January 23, 2023 @07:53AM (#34488188)
You are missing some of the best, most useful git commands:

git diff

git log

git blame

git bisect

A major advantage of version control is being able to navigate history.

Re:Git Commands You Probably Do Not Need by u801e on Monday January 23, 2023 @08:42AM (#34488605)
One command I use that I haven't seen anyone mention so far is git apply. I use this to stage or edit diff hunks before committing. Basically, at least in vim, I can highlight part of the diff (along with the diff header) and pipe it to the git apply command with the --cached and --recount flags to stage or unstage changes.

This, at least in my opinion, is easier to use than the -p flag for git add or git reset, and provides much finer grained control over staging and unstaging compared to those commands.

Re:Git Commands You Probably Do Not Need by mbork_pl on Monday January 23, 2023 @12:20PM (#34491862)
Good point, though I cannot not mention that you seem to have reinvented (a portion of) Magit, only with a worse UI... ;-)
Re:Git Commands You Probably Do Not Need by u801e on Monday January 23, 2023 @02:13PM (#34493495)
Perhaps, but I don't have to change editors to use Magit, nor do I need any plugins to do it :)
Re:Git Commands You Probably Do Not Need by mariusor on Monday January 23, 2023 @09:27AM (#34489097)
I think the main usefulness of tig lies with it's interactive staging screen. It's basically the TUI version of git add -i.
Re:Git Commands You Probably Do Not Need by mbork_pl on Monday January 23, 2023 @11:02AM (#34490460)
Who needs `git pull`? It's just a footgun.