GitTips
git.wiki.kernel.org
git.wiki.kernel.org
Along with the ones provided by the git oh-my-zh plugin I have these[0].
Some examples
+ gco - git checkout
+ ga - git add
+ gc - git commit
+ gp - git push
+ gl - git pull
+ gpc - Pushes current branch to origin
+ gpcfl - Force pushes the current branch to origin using --force-with-lease
+ glc - Pulls curent branch from origin
This is my favourite though
function goops { git add -A "$@" && git commit --amend --no-edit && gpcfl }
Used like this `goops file`, it adds the file, amends the last commits and force pushes the branch. Super useful because I tend to realise I forgot something just after I push. Don't do this on shared branches though, force pushing should only happen to branches were you are the only one working on the branch or in coordination with anyone else working on the branch.
0: https://github.com/k0nserv/dotfiles/blob/master/files/zshrc....
Note that you should only ever do this if you are absolutely sure that you are the only person pushing to that branch.
You should consider using "--force-with-lease" instead of "--force". Otherwise you'll sooner or later overwrite a coworker's push without a trace. Maybe they'll notice know Git good enough to fix this, but it would still be very, very annoying.
EDIT: Changed "repository" to "branch", mention "--force-with-lease".
I would revise this to say the only person pushing to that branch. But yeah.
This is the kind of thing that makes it hard to see why git has become the One True DVCS - you can not just overwrite history but actually lose other people's work quite easily (presumably the commit also vanishes from their repo when they next pull?)
Force pushing is super powerful when you learn to use git properly, but it's also like a gun with no safety so it's easy to shoot yourself in the foot if you don't know what you are doing.
I've worked with multiple orgs where the convention for shared repos was to use branch names of the form <user>/<topic>, e.g. bowie/pipeline-v2. Such "user" branches should generally never be pushed to by anyone other than the dev they were named for. This has worked great to allow individuals to have visibility and/or backups of work-in-progress while avoiding lossage due to any branch cleanup prior to PR, etc.
I'm the maintainer so feel free to suggest ones.
After starting the git shell in the terminal (just git sh for the eponymous program) all command are simply the same as in git, only without git in front of them (so add, push, etc.). Aliases work as expected of course, so st for status, and d for diff are possible too.
These type of shells have the added benefit of a status prompt showing the basic git info, such as current branch and number of commits ahead or behind the tracked branch.
What I do have is loads of aliases for getting different logs and graphs, because all the sensible formatting options are impossible to remember. I would be lost without these. Straight from my bash profile:
# Quick summary git log variants (with and without hash, with condensed whitespace or tabs)
alias 'gl=git --no-pager log --pretty=tformat:"%ad %an: %s" --date=short -n 15'
alias 'gll=git --no-pager log --pretty=tformat:"%ad %h %an: %s" --date=short -n 15'
alias 'glxl=git --no-pager log --pretty=tformat:"%ad %H %an: %s" -n 15'
alias 'glt=git --no-pager log --pretty=tformat:"%ad%x09%an%x09%s" --date=short -n 15'
alias 'gllt=git --no-pager log --pretty=tformat:"%ad%x09%H%x09%an%x09%s" --date=short -n 15'
# Same, in reverse order, plus show slightly more entries (most recent won't scroll off top of screen)
alias 'glr=git --no-pager log --reverse --pretty=tformat:"%ad %an: %s" --date=short -n 25'
alias 'gllr=git --no-pager log --reverse --pretty=tformat:"%ad %h %an: %s" --date=short -n 25'
alias 'gltr=git --no-pager log --reverse --pretty=tformat:"%ad%x09%an%x09%s" --date=short -n 25'
alias 'glltr=git --no-pager log --reverse --pretty=tformat:"%ad%x09%H%x09%an%x09%s" --date=short -n 25'
# Quick Git Graph viewing
# Usage: gg <list of branches> | gg --all
alias 'gg=git --no-pager log --decorate --oneline --graph -n 25'
alias 'gga=gg --all'
There's a naming convention of 'gl' for 'git log' and 'gg' for 'git graph' where 'll' means "log, long" and "lxl" means "log, extra long". Adding 't' means tab-separated for piping & parsing, or copying into a spreadsheet and 'r' means reverse (which I would actually consider 'forwards' but I try to stick with git conventions even though it's the opposite of say, svn). I did not create every permutation, but all of these variants are useful quite often and if I try to run a variant that doesn't exist, I just add it quickly so it's there next time.gdh -- git diff HEAD (what have I modified since last commit)
gl -- git log --graph --oneline --all --decorate (ASCII graph of all commits on all branches)
If you prefer vi you can always use spacemacs …
If you prefer Atom or SublimeText, well then: come over to the light side of the Force grin
Also, _both_ vim and Emacs are horrible UI. Vi was designed for slow terminals and a particular keyboard with no arrows; ghjk for navigation is terrible, always pressing the wrong key. Emacs was designed (C-w) evolved from macros for Space Cadet keyboard with lots of modifier keys. How these two archeological curiosities are still praised for being good modern text editors, escapes my mind.
(I use both vim and Emacs as I enjoy working in terminal, and I hate them both. Sadly, there is no good text editor like Sublime or Atom for console).
I have gone on the editor search for a while, and now I have settled. Can't be more happy!
The editors I might switch to are Acme, LightTable, or Lamdu, but probably unlikely.
M-x magit-init :-)
I'm not sure how much overlap there is in functionality, I have not even used all the features.
Here's a good blog article on it: http://blogs.atlassian.com/2013/05/git-tig/
[1] http://stackoverflow.com/questions/927358/how-to-undo-last-c...
[alias]
lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
[color]
branch = auto
diff = auto
interactive = auto
status = auto
[0]: http://blog.kfish.org/2010/04/git-lola.htmlI've tried it and this is not true on my git version (1.9.1) - without the "--abbrev-commit", git displays the full hash
http://www.syntevo.com/smartgit/
It gives you so much more visibility into the state of your repo, and many operations that take several Git commands are just a single step in SmartGit. And it does show you the underlying commands it uses.
I like the way SmartGit unifies things like the reflog. If you "lose" some commits because of an amended commit or a rebase gone bad, you don't have to hunt through the reflog looking at hashes and commit messages, just click the Recyclable Commits checkbox and everything in the reflog shows up as normal commits in your log. You can immediately look through these commits and see the changes without having to check them out.
I've also heard good things about SourceTree, but I can definitely vouch for SmartGit.
alias gitfire='git checkout -b fire-`date +"%Y%m%d-%H%M%S"` && git add -A && git commit -am "The roof is on fire" && git push origin HEAD'On the inside, Git is a thing of beauty, marvel of engineering. On the outside, it is a mess of inconsistent command line options, terrible documentation, and snobbish community that thinks everything of this is fine and small surface details are irrelevant as long as the core works exactly as advertised. They probably also work in Emacs with default keymap.
+1 for Mercurial.
If, like me, you do not have a good memory for arbitrary syntax, then mercurial is a lot easier. Takes a bit of cognitive load away from using your VCS. It is thus also much easier to learn than git, so the cost of giving it a whirl is much lower.
It also has that nice feeling of being designed with the end user interface in mind, which is satisfying if you care about such things. I enjoy using tools that give me clarity about what I'm doing, and mercurial achieves this by carefully separating the different actions VCS must support.
(I regularly use both systems and have done so for years. I am not a power user. I use mercurial whenever I have a choice).
The core working exactly as advertised is vitally important! Rotten core + shiny, 'user-friendly' exterior would be a polished turd.
I do agree - the outside of git didn't have to be ugly and I'm yet to meet any git 'apologist' who disagrees or thinks it's fine. In mitigation though, the git command can be wrapped by friendlier CLI tools or GUIs. Git has succeeded largely in part of the massive tooling around it - things like GitHub would have been less likely to exist had Git's internal data structures been opaque or poorly designed.
It might be instructive to hear it from the horses mouth: Linux, on git "git actually has a simple design, with stable and reasonably well-documented data structures. In fact, I'm a huge proponent of designing your code around the data, rather than the other way around, and I think it's one of the reasons git has been fairly successful […] I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important."