No Comments Git

[Git] Automatically add branch name on commits.

In order to have a more readable log, I generally prefer to add the branch name in each commit. It gives something in this flavor:
[myCurrentBranch] Some interesting things I fixed.
But it’s a pain to manually add it each time. Moreover each thing you manually do is human and then error prone. Let’s automatize that as good and lazy engineers / programmers as we are…

HowTo:

In your repository, rename the hook .git/prepare-commit-msg.sample to .git/prepare-commit-msg
Add the following code just before the “case”:
branchName=`git rev-parse --abbrev-ref HEAD`
echo "[$branchName] " > "$1.msg"
cat "$1" >> "$1.msg"
cat "$1.msg" > "$1"

Less things to type! Hurray!

No Comments Git

[Git] Remember credentials on git operations

Tired of entering your ID / password each time you do a git operation?
Here you go if you are on Windows:

Note: if you are using CygWin, you may change the following block with a CygWin style path:
[credential]
helper = !'C:\\Users\\myUserName\\AppData\\Roaming\\GitCredStore\\git-credential-winstore.exe'

into
[credential]
helper = !'/c/Users/myUserName/AppData/Roaming/GitCredStore/git-credential-winstore.exe'

No Comments Git, IT

[Git] Git 1.8 or higher in cygwin

Why update cygwin default git (v1.7.4)?

=> in the old version, git pull will linearize your history if you have a merge commit in it.
An alternative for that is:
git fetch
git rebase --preserve-merges

Do you want to have so much commands? Neh
=> in the 1.8.5, you only need to do that one time and then normally use git pull:
git config pull.rebase preserve # Do it one time

How To?

git clone https://github.com/git/git.git
cd git
git checkout v.1.8.5 # Or any version you want

In Makefile, replace the following line:
MSGFMT = msgfmtby
MSGFMT = msgfmt.py

make configure NO_MSGFMT_EXTENDED_OPTIONS=1
./configure
make NO_MSGFMT_EXTENDED_OPTIONS=1
make install NO_MSGFMT_EXTENDED_OPTIONS=1

Troubleshooting:

  • You will need the following packages from cygwin installer:
    • iconv-devel
    • make
    • dos2unix (optional)
    • autoconf
    • zlib-devel
    • libcurl-devel (otherwise https protocol won’t work. It is widely used by host providers. e.g: GitHub, BitBucket, …)
  • If it complains about some “\r”, change the endline of the concerned files with dos2unix