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…
Lesser known Git commands
81–90 of 142 posts
Re: Lesser known Git commands
#82My 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
$ git help push-pull
`git push-pull' is aliased to `!git pull --rebase && git push'Re: Lesser known Git commands
#83git (c)ommit --(a)mend --(n)o-(e)dit
Re: Lesser known Git commands
#84Warning: not actually git commands, rather TFAA's aliases for possibly useful combinations of switches and/or commands.
See, switches in git are there because git maintains backward compatibility. Sometimes a switch really would logically be better as a whole new command. But it's a common refrain to hear that git hides useful things in the switches. This article is a great way to find those hidden things.
Re: Lesser known Git commands
#85Warning: not actually git commands, rather TFAA's aliases for possibly useful combinations of switches and/or commands.
Yes, the title is misleading. edit: downvote?
The switches given to git commands in the article might be lesser-known, but title could be clearer that this is:
> Some suggestions for git aliasesRe: Lesser known Git commands
#86 git alias start 'checkout @{u} -B'
All my branches track origin/master (rather than local master), which makes it easy to git push / git pull without extra arguments. This will checkout a new branch from whatever the current branch is tracking. Usage: `git start my-new-feature` git alias track 'track = branch --set-upstream-to'
Sets up your current branch to track some other branch. Usage: `git track origin/master`. git alias gcbr 'gcbr = !git branch --no-track --no-color --merged | sed 's/[ *]*//' | grep -v master | xargs -n1 git branch -d &> /dev/null || exit 0'
"Garbage Collect BRanches" will delete any branches which are already merged into your current branch (excluding master). Basically, any branch which is "safe" to delete. (This one has been handed down through the ages; I initially found it on the skeleton dotfiles when I started working at Facebook. Thanks, whoever!)Re: Lesser known Git commands
#87 git diff origin/master -- test.file
It will show you a diff of a file between the master branch of remote origin and your local branch. I use it way more than I can think of.Re: Lesser known Git commands
#88Re: Lesser known Git commands
#89Some of the aliases are funny but could be renamed for brevity. Also grog is making me feel extremely groggy.
I would have named it "git rum"
Re: Lesser known Git commands
#90Earlier quoted context omitted.
> do people actually find stashing easier than branching? Branching wouldn't be enough, you'd need to commit your entire working copy to approximate a stash. I'd say it's generally a bug-prone mistake any time you commit your entire working copy (rather than staging lines/hunks on a one-commit-per-feature/bug basis). So branching and committing and pushing into a `backupForTomorrow` branch is fine, but you have to be…
> Branching wouldn't be enough, you'd need to commit ... Yes, you're right. I mentioned both committing I branching. I imagine commits only as the alternative to a single stash/pop, and commits & branching as the alternative to using multiple stashes. > I'd say it's generally a bug-prone mistake any time you commit your entire working copy The workflow I'd use instead of stash is to commit, do things, then reset --so…
- Paired operations `git stash` / `git stash pop` to quickly get rid of everything then reapply it a few minutes later.
- Stash as a "I probably don't want this code, but may as well keep a stashed copy" alternative to a hard reset. These stashes all then show up in my SourceTree sidebar to easily peruse or apply if needed (or copy/paste individual lines). Not a big deal if lost.
If I'm actually backing up code that I'll likely use, or need a remote backup of my current working copy to protect against laptop theft or HDD failure, I'll branch/commit/push the backup. Then use a mixed reset later to get rid of the commit itself and return everything to the working copy.