• tyler@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    You can use - everywhere you can use a ref in a git command. I very often use

    git checkout master
    git pull
    git checkout -
    git merge -
    

    (Of course that’s all aliased and I have other flags in there too, but that’s the gist)

    • NostraDavid@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      4 months ago

      Same for cd -. Nice if you want to go to /etc/blah, and then back to where you were.

      You can also use pushd and popd which will push and pop directories from a stack, if you need to do something more complex.

      Also, if you want to switch faster between branches, slap this in your ~/.gitconfig under [alias]:

      co = !git checkout $(git for-each-ref refs/heads/ --format='%(refname:short)' | fzf)

      Presuming you’ve got fzf installed, you can now git co (co = checkout) to get a menu with fuzzy find capabilities to switch between branches. Nice if branch names are long/similar/only-different-at-the-end.

      fzf is dope.