Skip to content

Instantly share code, notes, and snippets.

@drj11
Last active May 23, 2016 15:33
Show Gist options
  • Save drj11/d066d3c9283a7797fbb02bf0095f4e17 to your computer and use it in GitHub Desktop.
Save drj11/d066d3c9283a7797fbb02bf0095f4e17 to your computer and use it in GitHub Desktop.
10 most git
$ grep ^git ~/.bash_history | sort | uniq -c | sort -rn | head
     37 git diff
     22 git status
     20 git push origin HEAD
     16 git commit -a -v
      8 git rebase
      6 git fetch
      5 git commit -v
      5 git checkout develop
      4 git stash pop
      3 git log --decorate --oneline --graph --all

Where Am I?

git status, git diff, and git log --decorate --oneline --graph --all are three of the most useful commands. Especially for orienting yourself in space.

Run them before and after any tricky operation (especially the last one).

Run them when you've freshly cded into a directory and it's a monday morning and you have no idea what happened.

Pay particular attention to the output of git status. It seems like it's full of boring stuff, but often what the answer to your question is right there in the output. From "what branch am I on?", to "how do I avoid committing a file I accidentally added?", to "this git rebase has gone horribly wrong; how do I start over again?". It's all in the output of git status.

git push

In fact, if I type git push right now, what do I get?

drj@mus:~/prj/refinery-platform/deployment$ git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behaviour, use:

  git config --global push.default matching

To squelch this message and adopt the new behaviour now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behaviour, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

fatal: The current branch drj11/rds-endpoint has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin drj11/rds-endpoint

Ah. Meh. Who has time to read all that, and understand the change from "incomprehensible behaviour type A" to "incomprehensible behaviour type B"?

git push origin HEAD

is almost always what you want, and, by way of sharing syntax, introduces you to the more advanced uses of git push that you may see later on in your git adventures (such as pushing to different remotes, and deleting branches on remotes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment