Live data from Hacker News

Lesser known Git commands

hackernoon.com

121–130 of 142 posts

Re: Lesser known Git commands

#121
For every repo I fork I usually add a remote named upstream pointing to the original.

So then, whenever I need to get my copy up to date with upstream it's:

    update = !git fetch upstream && git merge upstream/master'
It's probably easily changed to make the branch configurable, but I have only ever needed this with master.

Re: Lesser known Git commands

#122
post #16

I've seen more stash accidents than any other kind with git. Stashing is more dangerous than committing or branching, and to me it doesn't seem to provide any advantages... do people actually find stashing easier than branching? Is it just because when you branch you have to name it, and that causes friction? I stay away from stash. Right from the man page: "If you mistakenly drop or clear stashes, they cannot be rec…

I use stash when I forget to branch. So I might be working and then realize I never branched. So I stash my changes, create a new branch, and then pop my changes on the new branch.

Why not branch some moment after realizing you forgot to and then go back to the (now gone a bit far) original branch and reset it to the original commit?

Simple and does not require any arcane tricks.

Re: Lesser known Git commands

#123

I'm still getting to know Git, and I appreciate articles like this as they touch on approaches to Git that have benefits in the real world, but I can't help but feel that version control tools should be simpler. Does anyone have any experience with version control tools that have worked out simpler to use than Git? I've heard good things about Darcs before (aside from its performance issues, which projects like Pijul…

It depends what you're using it for. Many people use Windows every day without knowing things like how to remap a network drive--but it's nice to have it there when you need it.

If you're by yourself and just need to keep a linear history all you need is 'git init' 'git add' and 'git commit'--if that's all you ever need, svn or any version control should work about equally well. But if you do need remote repositories, branches, rewriting your history, or commit hooks, it's there waiting if you're using git.

I feel like most of the different version control systems differ on those advanced features or how it scales for special needs. Git is great for decentralized and remote work, Perforce is better at handling histories with large binary files, etc. The basic features are fairly similar between them. Maybe there's a gui you like or a specific workflow, but I feel like that's a subjective choice.

Re: Lesser known Git commands

#125
post #16

I've seen more stash accidents than any other kind with git. Stashing is more dangerous than committing or branching, and to me it doesn't seem to provide any advantages... do people actually find stashing easier than branching? Is it just because when you branch you have to name it, and that causes friction? I stay away from stash. Right from the man page: "If you mistakenly drop or clear stashes, they cannot be rec…

> do people actually find stashing easier than branching? Absolutely. I stash things all the time. I find feature branches only useful for pull requests. My own code never uses feature branches unless I'm unsure of where I'm headed with the feature—I'll need to continually come back to it and build it a little at a time. But that's very rare. > Right from the man page: "If you mistakenly drop or clear stashes, they c…

I have more than 400 stashes… it turns out it's quite often that I find my current approach completely wrong and want to do a hard reset. But I don't do a hard reset but I stash it so during my next attempt I can still see it.

Re: Lesser known Git commands

#126
post #62

Earlier quoted context omitted.

I don't know if you're aware, so this is just a friendly suggestion: if you define these as git aliases instead, you won't use your shell's namespace and have it available for other aliases. As git aliases you would run it like `git s` or `git ca`. If you also alias git to g it will be `g ca`. If you do that, don't forget to call `__git_complete g __git_main` in .bashrc for it to auto-complete aliases for `g` and not…

I am of course aware of git aliases (e.g. because OP uses them a lot) but it never occured to me specifically to shorten git to g and find a way to keep autocomplete working. However, since these are by far my most typed commands (specifically, probably 40% of my executed commands are `s`), I strongly care about the difference even between 1 and 3 keystrokes. Thanks for your feedback. I wonder if the downvote was bec…

I never downvote anything, so I'm not sure, but maybe the use of "advise" and "canon" triggered negative votes?

Re: Lesser known Git commands

#127
post #16

I've seen more stash accidents than any other kind with git. Stashing is more dangerous than committing or branching, and to me it doesn't seem to provide any advantages... do people actually find stashing easier than branching? Is it just because when you branch you have to name it, and that causes friction? I stay away from stash. Right from the man page: "If you mistakenly drop or clear stashes, they cannot be rec…

Honestly I stash only cause I don't fully understand how to branch and bring my changes with me when I realize I should have branched earlier

Re: Lesser known Git commands

#128
post #16

I've seen more stash accidents than any other kind with git. Stashing is more dangerous than committing or branching, and to me it doesn't seem to provide any advantages... do people actually find stashing easier than branching? Is it just because when you branch you have to name it, and that causes friction? I stay away from stash. Right from the man page: "If you mistakenly drop or clear stashes, they cannot be rec…

I frequently swap between branches, for code review, or to move temporarily to something else for a short time.

I decide whether to commit what I have done or whether to stash it for now, based on what state it is in.

If I am still in the exploratory stage of the work, I usually wont commit, I will just stash and come back to it later.

Its a useful thing to be able to do at time when i am not yet ready to COMMIT to the changes I have made.

Re: Lesser known Git commands

#129

I'm still getting to know Git, and I appreciate articles like this as they touch on approaches to Git that have benefits in the real world, but I can't help but feel that version control tools should be simpler. Does anyone have any experience with version control tools that have worked out simpler to use than Git? I've heard good things about Darcs before (aside from its performance issues, which projects like Pijul…

What you want is svn.

Re: Lesser known Git commands

#130
My two favourite aliases :

    mo = ls-files -m
    lol = log --oneline --decorate --graph
`git mo tests/` gets you modified files for the tests folder.

`git lol` I think as the command line version of gitk

Post reply on HN