World map

 

BM: Baca dalam Bahasa Melayu

World 10: Deep Git

Aliases, includeIf, line endings

You will learn: three config powers: short names, settings per folder, and calm line endings.

The problem

git log --oneline --graph --all draws the diary's two commits. Terminal output: $ git log --oneline --graph --all * e0b2bc1 (HEAD -> main) Add day 2 * 04b414e Add home page

You type this long command twenty times a day. That is a lot of keys! Can Git give it a short name?

Try it

An alias: Your own short name for a Git command, like git st for git status. is your own short name for a command. Build one: git lg will draw your history.

Tap the pieces in the right order.

…

Try it

Now make git st mean git status. Then try it.

Predict

You make an alias called status that runs log. What does git status do now?

Pick one answer.

Watch

bash
cat ~/.gitconfig
[user]
name = Aina
email = aina@example.com
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
cat ~/.gitconfig-work
[user]
email = aina@company.example
Aina's ~/.gitconfig has her name and email, then an includeIf for gitdir ~/work/ that loads ~/.gitconfig-work. That file sets her work email.

includeIf: A config rule that loads extra settings only in some folders. loads extra settings in some folders only. Every repo inside ~/work/ uses Aina’s work email.

Try it

line ending: The invisible mark at the end of each line. Windows uses CRLF; macOS and Linux use LF. differ: Windows uses CRLF, Mac and Linux use LF. A .gitattributes: A file in your repo that tells Git how to treat some files, like line endings or binary files. file sets one rule for the whole team. Make one and commit it.

Working folder
  • Empty
Staging area
  • Empty
Repository
  • 2 save points
  • Add day 2
  • Add home page

Check

Which tool does each job?

Drag a card into a box. Or tap the card, then tap the box.

        You did it!

        You can now shorten commands, set folder rules and calm line endings.

        Go deeper (optional)

        On Windows, git config --global core.autocrlf true gives CRLF on your desk and LF in Git. On Mac or Linux, use input. Put includeIf after [user], so its email wins. An alias that starts with ! runs a shell command. Line endings already messy? See the World 11 lesson “Windows line-ending chaos”.

        Two aliases are set. --get-regexp alias lists alias.st status and alias.last log -1 HEAD. Terminal output: $ git config --global alias.st status $ git config --global alias.last "log -1 HEAD" $ git config --global --get-regexp alias alias.st status alias.last log -1 HEAD