Lesson 2 / الدرس 2

Installing git, and telling it who you are / تثبيت git وتعريفه بمن أنت

Two commands to check it is there, and three to configure it. The name and email you set here are stamped on every commit you will ever make, so it is worth getting right the first time.

أمران للتحقق من وجوده، وثلاثة لضبطه. والاسم والبريد اللذان تضبطهما هنا مختومان على كل commit ستصنعها، فيستحقان الضبط الصحيح من أول مرة.

git --version               is it already installed?

brew install git            macOS
sudo apt install git        Ubuntu, Debian, WSL
sudo dnf install git        Fedora
Check before you install — this is lesson 20 of the terminal course in practice. Git ships with many systems already, and on macOS running git --version the first time may offer to install the developer tools for you.

Who you are, on every commit

git config --global user.name "Ahmed Hamdi"
git config --global user.email "ahmed@example.com"
git config --global init.defaultBranch main

git config --list           see everything that is set
git config user.email       see one value
Run these three once per machine. --global means "for me, everywhere" and writes to ~/.gitconfig — one of the hidden files from lesson 11 of the terminal course. Run the demonstration for what each one affects.

The email is worth a moment of thought. It appears in the history of every project you contribute to, including public ones, so it is genuinely public. Use an address you are happy to have there — and if you would rather not publish a personal one, GitHub can give you a no-reply address that still links commits to your account. Lesson 16 comes back to this.

Three levels of configuration

LevelFlagStored inApplies to
System--system/etc/gitconfigEvery user on the machine
Global--global~/.gitconfigYou, in every project
Localno flag.git/configThis one project only

The most specific wins, so a local setting overrides your global one. That is how you use a work email in one project and a personal one everywhere else: set the global once, and override it inside that project.

Two more settings worth adding now, both of which prevent a category of confusion later. git config --global pull.rebase false tells git how to combine work when you pull, and stops it asking every time. git config --global core.autocrlf handles the fact that Windows and everything else disagree about line endings — input on macOS and Linux, true on Windows.

Try it live / جرّب بنفسك

Preview / المعاينة

Check yourself / اختبر نفسك

1. You set user.email after making ten commits. What happens to them?

2. What does --global mean?

3. Why set init.defaultBranch main?

Your task / مهمتك

Install or verify git on your machine and configure it properly. Report the version you have, the three settings you made, and the contents of your ~/.gitconfig afterwards. Then explain, in one paragraph, why the email address you chose is the one you chose — remembering that it will be visible in every project you contribute to.

ثبّت git أو تحقق منه على جهازك واضبطه كما ينبغي. وأبلغ عن النسخة التي عندك، والإعدادات الثلاثة التي ضبطتها، ومحتوى ~/.gitconfig بعدها. ثم اشرح في فقرة لماذا اخترت عنوان البريد الذي اخترته — متذكرًا أنه سيكون مرئيًا في كل مشروع تسهم فيه.

  • Your real git version نسخة git الحقيقية عندك
  • The three settings, and your real .gitconfig after الإعدادات الثلاثة، و.gitconfig الحقيقي بعدها
  • A reason for the email address you chose سبب اختيارك عنوان البريد
  • It is set BEFORE your first commit مضبوط قبل أول commit
How do you want to submit? / كيف تريد التسليم؟