-
jessehs
Developer
Git is great! Git is essential if you want to be a contributor to Drupal. Use it to work on a project, even without being connected to the internet. Make commits, merge branches, roll patches. Take the time to learn its very powerful features. Then use these tips to speed up your life! For example, why would you choose to type three characters when you can type one? Or, why type nine when you can type three?
Did you know about shell aliases? I have one in my ~/.profile (akin to a ~/.bashrc file for Linux users):
alias g='git '
This means I can type "g" and it really means "git".
Just like shell aliases, Git has its own form of aliases. There are commands you can type in the terminal to make configurations, but I find it easier to edit the ~/.gitconfig file directly. Begin the listing of aliases with [alias], then follow with a list of aliases, one per line. I use the following time-saving aliases in my .gitconfig file, picked up from various sources around the web:
[alias] s = status l = log --graph --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset' ll = log --stat --abbrev-commit d = diff co = checkout a = add ap = add -p patch = format-patch --stdout HEAD~1 rpatch = reset --hard HEAD~1
Interestingly enough, using the "g" bash alias in conjunction with an alias like "l" that might also have a bash alias defined results in a conflict. I don't know what to do about that. Oh, well. The "patch" and "rpatch" aliases are some of my favorite. Let's say I modified a contrib module and made a commit on it locally. (Just one commit.) I want to submit this commit as a patch to the module's issue queue. In the module's root directory, I type "g patch > /tmp/issue_description-1234567-4.patch". This takes the diff between the latest commit and the project before that, and formats a patch, which also includes authorship information! Next, I type "git rpatch". This removes all trace of the last commit (the one I made), so it now matches the way it still looks on drupal.org.
See my post a few weeks ago about showing the Drush site alias in the command prompt. This also works with the current Git branch as well. I believe Adam's dotfiles repo has an implementation of this.
In the ~/.gitconfig file, add this:
[url "git+ssh://jessehs@git.drupal.org/project/"] insteadOf = mod:
Tagged as: Drupal Planet, git, tips and tricks, tools of the trade
It's not checkout
It's not "git checkout mod:views" it's "git clone mod:views"
Add your comment