213

When you stare into git, git stares back.

It's fucking infinite.

Me 2 years ago:
"uh was it git fetch or git pull?"

Me 1 year ago:
"Look, I printed these 5 git commands on a laptop sticker, this is all I need for my workflow! branch, pull, commit, merge, push! Git is easy!"

Me now:
"Hold my beer, I'll just do git format-patch -k --stdout HEAD..feature -- script.js | git am -3 -k to steal that file from your branch, then git rebase master && git rebase -i HEAD~$(git rev-list --count master..HEAD) to clean up the commit messages, and a git branch --merged | grep -v "\*" | xargs -n 1 git branch -d to clean up the branches, oh lets see how many words you've added with git diff --word-diff=porcelain | grep -e '^+[^+]' | wc -w, hmm maybe I should alias some of this stuff..."

Do you have any git tricks/favorites which you use so often that you've aliased them?

Comments
  • 34
    I'm in awe
  • 18
    Okay, that's pretty good 😀

    Teach me Sensei!
  • 13
    Oh! Oh ! I've been using one of these for a while now 😊
    git branch - - merged....
    Aliased to "spring" for "spring cleaning"
  • 77
    alias bf = 'git commit -m "bug fixes and minor improvements"'
  • 16
    Barely at the one year ago stage, rn😅

    last paragraph : Bamboozling 😮
  • 16
    Oh well I gotta study those alien git commands at the bottom of your post 🧐
  • 6
    If you don't know git, this site won't help you either:
    https://git-man-page-generator.lokaltog.net/...
  • 9
    @Bitwise On the other hand wget <full github url>.diff | git am -3 && git add -p...

    Interactively staging snippets of code from any github page to your current working branch (assuming the github page is showing any relevant changes). I've used this to quickly steal configs from unrelated repositories.
  • 6
    alias git-check='echo "↓$(git rev-list --left-right --count origin/master...)↑"'

    To show how many commits I'm behind and ahead of origin/master.
  • 4
    @TheSilent Neat! Super useful to set as a part of the prompt 😊
  • 4
    📌 I can learn from you git gurus
  • 3
  • 5
    Man, I've always used merge and discovered rebase two days ago.

    I wanna die.
  • 3
    @TheSilent umm. This can be done by git status -sb
  • 3
    I simply love the program, it is simple and does (quite a ) few things and does it well!

    My fav alias is Git history which is my custom format of Git log
  • 6
    git yolo => git commit -am "Stuff" && git pull -f && git push -f

    I used to do that :/, one of my coworkers didn't like it

    PS don't kill me
  • 6
    I also love `git cherry-pick commitHash`, which applies the commit to the current HEAD, if applicable.

    Also `git bisect` is very useful if you know that a bug is introduced, and you want to know own which commit introduced that bug. It uses binary search. :)
  • 4
    I still rely on this one when I setup a new dev pc

    https://code.tutsplus.com/tutorials...
  • 5
    Now I definitely want to learn GIT commands like that
  • 8
    @Rocket3G Bisect! I use that in a script combined with composer & npm/yarn, put every dependency version upgrade in a seperate commit, run unit tests. Rebase/squash on success, bisect/test on fail to find packages with breaking changes 😉
  • 2
  • 3
    I learnt git basics 4 years ago, using command line. But since I feel comfortable with it I'm lazy, so I just use SourceTree. It has many ui bugs but it does a great job as an everyday git client. I could go back to cli but it would feel uselessly painful.

    But the real thing I love is git-flow. That simple workflow totally change the game: it's so clean and efficient, it simplifies team work a lot, it helps using semver, and once you get it it's actually a very obvious way to work.
  • 3
    I guess im in stage two
  • 2
    @Masta I think it's awesome that gui clients exist. Git would be hard to sell to less neckbeardy types if all you had was the terminal.

    Still, I personally like to "reformat" bigger complicated branches before making PRs, using rebase -i, squashing and rewriting commit messages. I move chunks of edits between commits, so single commits represent a "package" of changes — that way, they're easier to review, revert or browse through in the future.
  • 3
    @yendenikhil It's actually not the same since git status -sb only shows the difference between your branch and its remote counterpart (If I'm not mistaken here).
    I wanted to compare to origin/master specifically no matter the branch I'm on ;)
  • 4
    @TheSilent isn't it bit dangerous? I mean origin master and your local branch is evolving differently as time passes!
  • 3
    @yendenikhil That's exactly the reason I use it. I normally rebase my branch when I'm behind master. So what I do is git-check and then rebase of necessary ;)
  • 4
    @TheSilent have it your way then! 😁
  • 2
    glol

    For git log --oneline

    [G]it [L]og [O]ne [L]ine

    It's easy to remember, it is used frequently and it has lol in it. Top that.
  • 4
    If you use zsh, it already provides you with so many aliases:
    gst - git status
    gco - git checkout
    glo - git log
    .....
    The list goes on and on
  • 1
    My best git trick is using sourceTree.
  • 3
    @Bitwise hey thanks mate. I didn't know that git format-patch was important too. I'll study it later 😎
  • 3
    @varundey thanks for the glo. I use glog
  • 3
    Imma pin this so I can learn
  • 6
    @junners Careful, learning is an addiction which eventually leads to the realization that others are blissfully retarded, the depressing revelation that you're not going to change that, resulting in a final state of permanent misanthropy.

    But fine, join the club.
  • 2
    @bittersweet addiction indeed. A sweet addiction which you have to bust your ass and bang your head to the wall multiple times before saying "Aha, piece of cake!!"
  • 5
    @Bitwise I'm in!

    But please let us not combine the coffee-house and the acid. I prefer it chill when I'm tripping.
  • 5
    @bittersweet I think I've already reached terminal misanthropy :<

    @Bitwise That's quite the compliment. Thank you 😊
  • 1
  • 1
    M-x magit-status RET can be considered an alias?
  • 1
    The Git is strong in this one
  • 2
    Git push --force
    That's all I need
  • 2
    Git push --force
    That's all I need
  • 1
    I’m most familiar with git revert 3daf84bce20 —no-edit because of stupid bugs that nobody caught.
  • 3
    @creator go wash your terminal with water and soap you filthy man.

    (although, no problem if you fully "own" the remote feature branch — like when working solo on a PR)
  • 3
  • 2
    I still forget to put my commit messages inside "" sometimes.. so well done you!
  • 2
    I would just like to say thank you to everyone who commented here and made this thread the most useful rant i ever saw. :)
  • 1
  • 0
    I learned a new one .. not related to git commands but useful in cmd :
    1) cd .. :to get back one diredtory
    Eg you are in cd/Desktop
    >> ~/Desktop $ cd ..
    >> ~$

    2) while in a repo, if you want to go to folder, just type 2-3 characters of its name after cd and press TAB, it will auto-complete ;)
    >> ~ $ cd Des[press Tab will make it Desktop/]
    >> ~/Desktop $
Add Comment