Better git log

First of all if you don’t have set utf-8 in bash (test with locale command or just try to type utf-8 characters in cli) you need to add export LANG=C.UTF-8 to your ~/.bashrc file:

echo 'export LANG=C.UTF-8' >> ~/.bashrc

Next you can format your command. We will show only commits on master branch with no merges:

git log master --pretty=format:"%C(blue)%cd %C(green)%cn %C(blue)%s %C(yellow)%h" -n10 --no-merges --date=short"

And optionally set alias in your ~/.bashrc:

echo 'alias gl="git log master --pretty=format:\"%C(blue)%cd %C(green)%cn %C(blue)%s %C(yellow)%h\" -n10 --no-merges --date=short"' >> ~/.bashrc

Finally restart bash instance.

Now you can use command gl.

Showing git branch in bash prompt

To achieve something like this:

user@machine:~/myproject (develop)$

In .bashrc file at the end we need to add:

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[01;31m\]"
YELLOW="\[\033[01;33m\]"
GREEN="\[\033[01;32m\]"
BLUE="\[\033[01;34m\]"
NO_COLOR="\[\033[00m\]"
# without host
#PS1="$GREEN\u$NO_COLOR:$BLUE\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ "
# with host
PS1="$GREEN\u@\h$NO_COLOR:$BLUE\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ "

Make Git ignore file mode (chmod) changes

Per project

git config core.fileMode false

Global

git config --global core.fileMode false

Warning

Changes of the global setting won’t be applied to existing repositories. Additionally, git clone and git init explicitly set core.fileMode to true in the repo config as discussed in Git global core.fileMode false overridden locally on clone

Warning 2

core.fileMode is not the best practice and should be used carefully. This setting only covers the executable bit of mode and never the read/write bits. In many cases you think you need this setting because you did something like chmod -R 777, making all your files executable. But in most projects most files don’t need and should not be executable for security reasons.

The proper way to solve this kind of situation is to handle folder and file permission separately, with something like:

find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \; # Make files read/write
If you do that, you’ll never need to use core.fileMode, except in very rare environment.

Configuring Git to handle line endings

The git config core.autocrlf command is used to change how Git handles line endings. It takes a single argument.

On Linux, you simply pass input to the configuration. For example:

git config --global core.autocrlf input

# Configure Git to ensure line endings in files you checkout are correct for Linux