Live data from Hacker News

Lesser known Git commands

hackernoon.com

21–30 of 142 posts

Re: Lesser known Git commands

#21
> If in doubt, the long one (git staaash) will always restore your worktree to what looks like a fresh clone of your repository.

Not necessarily. This depends on what branch you're on as well as whether or not it's up to date with the remote.

Re: Lesser known Git commands

#22
post #12

My most useful bash alias (when you go back to master and want to start at the most up to date everything before creating a new branch): alias grm="git fetch origin && git reset --hard origin/master"

same here but I switch to master first:

resync = !git reset --hard HEAD && git checkout master && git reset --hard origin/master && git pull

or with a parameter to do the same with any branch:

resync = "!f() { git reset --hard HEAD && git checkout $1 && git reset --hard @{u} && git pull ; }; f"

Re: Lesser known Git commands

#25
post #2

Warning: not actually git commands, rather TFAA's aliases for possibly useful combinations of switches and/or commands.

I should really read more of the git doc but at least I learned about aliasing in the gitconfig from this even if, I too, was expecting actual git commands

Re: Lesser known Git commands

#26
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.

Makes sense, but fwiw, there's a safer alternative: branch immediately, then go back to the source branch and reset.

There's nothing wrong with your workflow, btw, stash works in that case, as long as you immediately pop & don't get interrupted by lunch or a phone call.

Stashing is obviously providing some value that people like, it's very popular. But considering that it has extra danger, and that it's really easy to work without stash, I'm still confused why it's so popular.

And fwiw, most of the stash accidents I've seen are fairly simple scenarios like you described, and some teeny tiny twist or interruption causes someone to get confused and lose their stash, or think they lost their stash, and panic.

Re: Lesser known Git commands

#27
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 stash? Why not just branch then commit?

Re: Lesser known Git commands

#28

> so it’s good practice to create an empty commit as your repository root While I'm aware of issues with rebasing the root commit, I've never heard this advice before and it seems unnecessary.

Rebasing the root commit has been possible for a while using `git rebase --root`.

http://stackoverflow.com/questions/30277149/how-to-use-inter... goes into more detail.

Re: Lesser known Git commands

#29

> so it’s good practice to create an empty commit as your repository root While I'm aware of issues with rebasing the root commit, I've never heard this advice before and it seems unnecessary.

There's also the `--root` flag for rebase, which solves this problem without needing the dummy commit. I think this section of the article is out of date.

Re: Lesser known Git commands

#30
post #6

My personal favorite two: jschroeder@omniscience:~$ git config alias.up pull --rebase jschroeder@omniscience:~$ git config alias.down push They can be used thusly: git up && git down

I like where your head's at and added a little something to help me here at work:

    void:~% git config alias.funky
    ! git up && git submodule update
And speaking of lesser known commands, I've been using 'git worktree' recently at work and I'm a big fan. Admittedly, it's probably mostly unknown because it's a new feature.

It's a little rough around the edges, but it has made things like customer support context switching much easier since I can leave my current development tree alone and just create a new worktree for the current escalation.

Post reply on HN