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
git --version the first time may offer to install the developer tools for you. git --version أول مرة تثبيت أدوات المطوّر لك.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
--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.
--global تعني "لي في كل مكان" وتكتب في ~/.gitconfig — أحد الملفات المخفية من الدرس 11 في دورة الطرفية. شغّل العرض لمعرفة ما يؤثر فيه كل واحد.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
| Level | Flag | Stored in | Applies to |
|---|---|---|---|
| System | --system | /etc/gitconfig | Every user on the machine |
| Global | --global | ~/.gitconfig | You, in every project |
| Local | no flag | .git/config | This 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.
git config --global pull.rebase false يخبر git كيف يجمع العمل حين تسحب، ويمنعه من السؤال في كل مرة. وgit config --global core.autocrlf يعالج اختلاف Windows عمّا عداه في نهايات الأسطر — input على macOS وLinux، وtrue على Windows.~/.gitconfig نفسه. وفتحه بـgit config --global --edit يريك كل شيء دفعة واحدة، وهو أسرع عادةً من التنقيب في شاشة إعدادات.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1.
You set user.email after making ten commits. What happens to them?
user.email بعد صنع عشر commits. ماذا يحدث لها؟The values are stamped at commit time. On GitHub, commits with an unrecognised address are not linked to your account.
2.
What does --global mean?
--global؟It writes to ~/.gitconfig, in your home directory. A setting inside one project overrides it, because the most specific level wins.
~/.gitconfig في مجلد منزلك. والإعداد داخل مشروع واحد يتغلب عليها، لأن المستوى الأخص يفوز.
3.
Why set init.defaultBranch main?
init.defaultBranch main؟Older git used master. Having your machine and GitHub agree from the start avoids a mismatch that is confusing to fix later.
master. واتفاق جهازك وGitHub من البداية يتجنّب اختلافًا يربك إصلاحه لاحقًا.Score / النتيجة: 0 / 3
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