If you find git confusing, I created this little cheat sheet! Please, note that I voluntary skipped the basic commands like git commit, git pull/pu...
For further actions, you may consider blocking this person and/or reporting abuse
My favorite git utility is "reuse recorded resolution"
git rerere
. Sometimes if you have multiple parallel branches and try to merge or rebase between them, you get the same conflict multiple times.git rerere
records your resolution and then just automatically applies it, if you encounter the same conflict again.And it's pretty much set it and forget it because it completely works autonomously in the background. git-scm.com/docs/git-rerere
I never heard about this one until now. It looks very handy! I'll give a try on my next conflict!
Thanks for sharing 👍
Found here: github.com/nicksp/dotfiles/blob/ma...
this config is... massive!!! 😯
Awesome article... congrats :)
My favourite and most used Git alias:
The
gwip
commits everything with the message--wip-- [skip ci]
. By everything I mean untracked files, changes not staged for commit, and changes already staged for commit.The
gunwip
revertsgwip
, with the caveat that changes already staged for commit will become changes not staged for commit.I use it to save my work until I am ready to create a proper commit.
Having
[skip ci]
in the commit message tell the Continuous Integration pipeline to ignore the commit.This is a great idea! This functionality should probably be included within git.
One idea that comes to my mind how you could complicate this (read: make it work "completely"). You could extend the script to open all the staged files and add a comment to the top of the file. Something like:
--staged--
. Then, when you "unwip", it can read that comment and stage/unstage files as needed, while also removing that comment.It already is, in a way.
If you do a
git stash -u
, it will create a commit for you that includes staged, unstaged and untracked files, and it knows which files were staged and which ones weren't. If you wanted to keep the changes that were stashed as they were, you can issue agit stash apply
immediately after (useapply
to keep the stash, orpop
to discard it after applying it).This is amazing! Thank you!
Git never seizes to amaze me for its unlimited functionality.
For applying the stash, you need add
--index
as in:git stash apply --index
. This will restore the index (staged/unstaged files) along with the file changes.Awesome cheat sheet, really. Learned quite a few things despite being quite advanced with git already.
I prefer my version of
git lg
(logs), which also displays the date of each commit in a neat format:gist.github.com/Vadorequest/9d1f86...
* f0d6b49 - wip (3 hours ago) <Me>
Love this one 😍 Thanks!!! Will update my dotfiles right now!
Excellent guide! I like the idea of git-standup. ☕
For alias, to work even with mistyping, I also use:
Also, one thing that was really useful for me is the meta repository of Matt Walters, so I can avoid git submodule and subtree to work with multiple repositories.
Nice article. I got to learn about a few things I didn't know about git before.
By the way
git save
is deprecated now, you should rather go bygit push -m
.And for the last section about git aliases, since I'm using bash I get all these aliases and much more when I install oh-my-bash.
Hmm.. where did I wrote a command with
git save
?About the aliases, I have something similar: Oh-my-zsh. But I extract those aliases in my personal dotfiles so I can get them everywhere I need them :)
Sorry, it seems I completely messed up the comment. I meant to use
git stash push -m
instead ofgit stash save
, as the latter is deprecated.you completely right Mohammed! Thanks for pointing this out :)
Improved version:
interesting! 😃
Nice post Maxence.
If you need to overwrite the master from the dev branch any time:
git branch -f master dev_branch [will rewrite local master branch.]
git push remote +dev_branch:master [will rewrite remote branch.]
Nice article, thank you for sharing. Want to some more favorite aliases to the list.
The
git -standup()
one in nice. Can you please explain a bit on how to use it?I love the
git-standup
function!Nice! :)
My favorite git aliases:
:D
we almost got the same! :D
Nice post! Thank you!
My aliases:
Thx for this! This is really what I wanted. Helped A LOT.
Can I translate in Korean this post? If you don't mind, I wanna share this awesome post in Korean. Surely, There will be a linke directing to this original post.
Hey, sure you can translate it in Korean. If you do so, could you please
I hope it's not too late :)
Nice summary! I'd like to translate it to Chinese (the translated text will be published at nextfe.com). Can you give me the permission?
Hey Jang, sorry for the late reply.
Sure! You can translate it in Chinese! :) (I just ask you to mention the original post + author)
Let me know when it's published!
Just published Chinese translation at: nextfe.com/git-cheatsheet-advanced/
Credit is given at the beginning of the translated text (also backlink to the original post).
BTW, in section "🕹Execute command on each commit when rebasing":
I think you meant to write
npm test
here (as shown in the figure below), despite thatnpm run test
andnpm test
are equivalent.Sorry for the very late reply but thank you!
The article gave a thoughtful process about rebasing. Thanks!
I'm glad you found it helpful 😃
Super article, au top ! 👌
Haha me voila demasqué ! Merci :)
Ahah ça va c'était pas bien compliqué ! 😁
Great post! Might be worth mentioning that for your
git diff master..my-branch
command - if you're already onmy-branch
, then you can omit themy-branch
- eg. justgit diff master..
thanks for the tip ;)
Love the article! Thanks for sharing. I recently changed my habit from doing
git add .
togit add -A
(--all
). The difference is, it does not matter if you in subdirectory or not.Thanks for sharing this!
When there a lot of commits it might take too much time. In such cases, git bisect comes to the rescue -- instead of executing a command on all commits it uses binary search to identify the first commit that breaks everything.
Perhaps, you might find this project useful: github.com/kamranahmedse/git-standup
Agree, bisect is the key when we have too many commits!
About git-standup, I don't really need it. I'm happy with my simple alias. I also grep a lot my git log :)
But, thanks for sharing! Someone else might found it handy!!!
well, you don't need to create a bash alias, you can create git alias for
alias glog='git log --oneline --decorate --graph'
such asgit config alias.glog ...
Hmmm for some reasons, I am not a big fan of git aliases :) (but I don't remember why haha)
Great article! Thank you.
Question: Where did you store the "alias-code" (from the last section "Bonus: my favourite git aliases") for it to take effect?
hey, to be transparent with you everything is on my dotfile repository!
👉 github.com/maxpou/dotfiles
(in a file called alias and I
source $HOME/.aliases
on my zshrc/bashrc)Very nice article
awesome git cheat sheet
Thanks for the feedback!
alias yolo='git push --force' 😅
nice isn't it? 😃
Very useful post! Thanks!
Awesome article, I'll find this useful as I struggle with Git. Thanks dude.
Thanks Mohammad :)
pretty good
This is brilliant! I learned a few new things, especially
hub
. I am gonna try it soon.Thanks @maxpou!
Great.
Thanks for sharing :)
alias yolo made me laugh hard :D
Haha I'm glad if you liked it!
I use this command everyday 😃
Thanks Sean :)