{"id":"l-git-1-2","courseId":"git-github","lang":"en","kind":"lesson","summary":"Install Git, set your name, email, default branch and editor once, then turn your portfolio folder into a repository and record its first commit.","html":"<p>Before Git can record anything, it needs two facts about you and a few preferences. You set these once per computer, and they quietly shape every commit you make for years. Ten minutes now saves you from hundreds of commits credited to “unknown” or an address you no longer own.</p>\n<h2 id=\"sec-1\" tabindex=\"-1\">Install Git</h2>\n<p>Check whether Git is already there:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"0\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --version</span></span></code></pre></div>\n<p>If you see something like <code dir=\"ltr\">git version 2.51.0</code>, you’re set; any 2.4x or newer version works for this course. If not:</p>\n<ul>\n<li><strong>macOS:</strong> running <code dir=\"ltr\">git --version</code> offers to install the Xcode Command Line Tools, which include Git. If you use Homebrew, <code dir=\"ltr\">brew install git</code> gets you a newer one.</li>\n<li><strong>Windows:</strong> install Git for Windows from git-scm.com. Keep the defaults; they include Git Bash (a terminal where every command in this course works) and Git Credential Manager, which you’ll use in section 3.</li>\n<li><strong>Linux:</strong> use your package manager, for example <code dir=\"ltr\">sudo apt install git</code> on Ubuntu or <code dir=\"ltr\">sudo dnf install git</code> on Fedora.</li>\n</ul>\n<h2 id=\"sec-2\" tabindex=\"-1\">Tell Git who you are</h2>\n<p>Every commit stores an author name and email. Set them globally, meaning for your user account on this machine:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"1\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> config</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --global</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> user.name</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> \"Maya Okafor\"</span></span>\n<span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> config</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --global</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> user.email</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> \"maya.okafor@example.com\"</span></span></code></pre></div>\n<p>The email matters more than it looks. GitHub decides whose avatar and profile appear next to a commit by matching the email inside it against the addresses on GitHub accounts. If you’d rather not publish your real address, GitHub gives every account a noreply address of the form <code dir=\"ltr\">12345678+username@users.noreply.github.com</code> (find yours under Settings, then Emails) and you can use that instead.</p>\n<aside class=\"callout callout-tip\" role=\"note\"><p class=\"callout-title\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5\"/><path d=\"M9 18h6\"/><path d=\"M10 22h4\"/></svg><span><span class=\"callout-kind\">Tip</span><span class=\"callout-sep\" aria-hidden=\"true\"> · </span>Keep your email private</span></p>\n<p>In GitHub’s email settings, turn on “Keep my email addresses private” and use the noreply address in <code dir=\"ltr\">user.email</code>. Your commits still link to your profile, and your inbox stays out of every public repository you touch.</p>\n</aside>\n<h2 id=\"sec-3\" tabindex=\"-1\">Three preferences worth setting now</h2>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"2\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> config</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --global</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> init.defaultBranch</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> main</span></span>\n<span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> config</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --global</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> core.editor</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> \"code --wait\"</span></span>\n<span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> config</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --global</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --list</span></span></code></pre></div>\n<ul>\n<li><code dir=\"ltr\">init.defaultBranch main</code> names the first branch of every new repository <code dir=\"ltr\">main</code>, which matches what GitHub creates. Without it, Git 2.x still names the first branch <code dir=\"ltr\">master</code> and prints a long hint about it.</li>\n<li><code dir=\"ltr\">core.editor</code> is the program Git opens when it needs you to write text, such as a commit message. Many installs default to Vim, which surprises people who don’t know it. <code dir=\"ltr\">code --wait</code> uses VS Code (the <code dir=\"ltr\">--wait</code> keeps Git waiting until you close the tab); <code dir=\"ltr\">nano</code> is a simple terminal option.</li>\n<li><code dir=\"ltr\">--list</code> prints what you’ve set so you can check for typos.</li>\n</ul>\n<p>These go into a plain text file, <code dir=\"ltr\">~/.gitconfig</code>. A setting without <code dir=\"ltr\">--global</code>, run inside a repository, applies only to that repository and overrides the global one. That’s handy if you want a work email in work repositories and a personal one everywhere else.</p>\n<h2 id=\"sec-4\" tabindex=\"-1\">Create the repository</h2>\n<p>Make a folder for your portfolio and turn it into a repository:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"3\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">mkdir</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> portfolio</span></span>\n<span class=\"line\"><span style=\"color:#0550AE;--shiki-dark:#79C0FF\">cd</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> portfolio</span></span>\n<span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> init</span></span></code></pre></div>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"text\" data-index=\"4\"><div class=\"code-head\"><span class=\"code-title\">Text</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code>Initialized empty Git repository in /Users/maya/portfolio/.git/</code></pre></div>\n<p>That hidden <code dir=\"ltr\">.git</code> folder is the repository: every commit, branch and setting for this project lives inside it. The files you edit sit next to it. Don’t edit anything inside <code dir=\"ltr\">.git</code> by hand, and know that deleting it deletes the history while leaving your current files alone.</p>\n<aside class=\"callout callout-mistake\" role=\"note\"><p class=\"callout-title\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\"/><path d=\"M12 9v4\"/><path d=\"M12 17h.01\"/></svg><span><span class=\"callout-kind\">Common mistake</span><span class=\"callout-sep\" aria-hidden=\"true\"> · </span>Running git init in the wrong folder</span></p>\n<p>If you run <code dir=\"ltr\">git init</code> in your home folder, Git wraps every file you own, and <code dir=\"ltr\">git status</code> lists your Desktop, Downloads and Documents as untracked. Check where you are with <code dir=\"ltr\">pwd</code> before <code dir=\"ltr\">git init</code>. If it already happened, delete the stray folder with <code dir=\"ltr\">rm -rf ~/.git</code> (only that one, and only if you never committed there), then run <code dir=\"ltr\">git init</code> inside <code dir=\"ltr\">portfolio</code>.</p>\n</aside>\n<h2 id=\"sec-5\" tabindex=\"-1\">Make the first commit</h2>\n<p>Create <code dir=\"ltr\">index.html</code> with a minimal page:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"html\" data-index=\"5\"><div class=\"code-head\"><span class=\"code-title\">index.html</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">&#x3C;!</span><span style=\"color:#116329;--shiki-dark:#7EE787\">doctype</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> html</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">&#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">html</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> lang</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">=</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\">\"en\"</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">  &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">head</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">    &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">meta</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> charset</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">=</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\">\"utf-8\"</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">    &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">title</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">>Maya Okafor&#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">title</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">  &#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">head</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">  &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">body</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">    &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">h1</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">>Maya Okafor&#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">h1</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">    &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">p</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">>Front-end developer in progress.&#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">p</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">  &#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">body</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">&#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">html</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span></code></pre></div>\n<p>Now ask Git what it sees:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"6\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> status</span></span></code></pre></div>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"text\" data-index=\"7\"><div class=\"code-head\"><span class=\"code-title\">Text</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code>On branch main\n\nNo commits yet\n\nUntracked files:\n  (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)\n\tindex.html\n\nnothing added to commit but untracked files present (use &quot;git add&quot; to track)</code></pre></div>\n<p><strong>Untracked</strong> means Git sees the file but has never recorded it. Committing is two steps: choose what goes in, then record it.</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"8\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> add</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> index.html</span></span>\n<span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> commit</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> -m</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> \"Add home page\"</span></span></code></pre></div>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"text\" data-index=\"9\"><div class=\"code-head\"><span class=\"code-title\">Text</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code>[main (root-commit) 3f9c2a1] Add home page\n 1 file changed, 11 insertions(+)\n create mode 100644 index.html</code></pre></div>\n<p>Read that output: you’re on <code dir=\"ltr\">main</code>, this is the <strong>root commit</strong> (the first one, with no parent), and its short ID is <code dir=\"ltr\">3f9c2a1</code>. Yours will differ, because the ID is a hash of the content, your name, the time and the parent. Run <code dir=\"ltr\">git log</code> to see the commit with its full ID, author and date.</p>\n<p>Why two steps instead of one? Because the gap between <code dir=\"ltr\">add</code> and <code dir=\"ltr\">commit</code> is where you decide what belongs together. That gap has a name, the staging area, and it’s the subject of the next lesson.</p>\n","toc":[{"id":"sec-1","text":"Install Git","level":2},{"id":"sec-2","text":"Tell Git who you are","level":2},{"id":"sec-3","text":"Three preferences worth setting now","level":2},{"id":"sec-4","text":"Create the repository","level":2},{"id":"sec-5","text":"Make the first commit","level":2}],"takeaways":["Run <code dir=\"ltr\">git config --global</code> once per machine for <code dir=\"ltr\">user.name</code>, <code dir=\"ltr\">user.email</code>, <code dir=\"ltr\">init.defaultBranch</code> and <code dir=\"ltr\">core.editor</code>; Git stores them in <code dir=\"ltr\">~/.gitconfig</code>.","Your commit email decides which GitHub account a commit is credited to, so use one your account knows, such as the noreply address.","<code dir=\"ltr\">git init</code> creates a hidden <code dir=\"ltr\">.git</code> folder; that folder is the repository, and deleting it deletes all history.","A commit is two steps, <code dir=\"ltr\">git add</code> to choose what goes in and <code dir=\"ltr\">git commit -m</code> to record it with a message."],"further":[{"title":"First-Time Git Setup (Pro Git)","url":"https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup"},{"title":"git config reference","url":"https://git-scm.com/docs/git-config"},{"title":"Setting your commit email address","url":"https://docs.github.com/en/account-and-profile/how-tos/email-preferences/setting-your-commit-email-address"}],"quiz":[{"q":"<p>You set <code dir=\"ltr\">user.email</code> to an old work address. Your commits push fine, but GitHub shows them with a grey, unlinked avatar. Why?</p>","options":[{"text":"The push failed silently and GitHub is showing a cached copy.","why":"The commits are on GitHub, so the push worked. The avatar problem is about who the commits say wrote them."},{"text":"GitHub only links commits made through its website.","why":"GitHub links commits from any client. It matches the email inside each commit to the emails on an account."},{"text":"You need to run <code dir=\"ltr\">git init</code> again to refresh the author.","why":"<code dir=\"ltr\">git init</code> on an existing repository changes nothing about authorship. Author details are written into each commit when it’s created."},{"text":"GitHub matches the email stored in each commit to an account, and that address isn’t on yours.","why":"Correct. Add the address to your GitHub account, or set <code dir=\"ltr\">user.email</code> to one it knows (such as your noreply address) for future commits."}],"answer":3},{"q":"<p>You run <code dir=\"ltr\">git commit</code> with no <code dir=\"ltr\">-m</code> and a full-screen editor you don’t recognise opens. What happened?</p>","options":[{"text":"Git crashed and opened its error log.","why":"Nothing crashed. Git asks for a message, and with no <code dir=\"ltr\">-m</code> it opens your configured editor to collect one."},{"text":"Git opened <code dir=\"ltr\">core.editor</code> (often Vim by default) so you can write the commit message.","why":"Correct. Write the message, save and close. Set <code dir=\"ltr\">core.editor</code> to an editor you know, such as <code dir=\"ltr\">code --wait</code> or <code dir=\"ltr\">nano</code>, to avoid surprises."},{"text":"The commit was made with an empty message and the editor shows the diff.","why":"Git refuses an empty message and aborts the commit. The editor is where the message goes before anything is recorded."}],"answer":1},{"q":"<p>You accidentally ran <code dir=\"ltr\">git init</code> in your home folder and now every directory shows up as “untracked”. What is the right fix?</p>","options":[{"text":"Run <code dir=\"ltr\">git init</code> again inside the <code dir=\"ltr\">portfolio</code> folder; the newer repository replaces the old one.","why":"The home-folder repository would still exist and still wrap everything. Nested repositories make things more confusing, not less."},{"text":"Run <code dir=\"ltr\">git reset --hard</code> in your home folder.","why":"That command acts on commits and the working tree. It could discard changes and still leaves the <code dir=\"ltr\">.git</code> folder in place."},{"text":"Remove the <code dir=\"ltr\">.git</code> folder from your home directory, then run <code dir=\"ltr\">git init</code> inside <code dir=\"ltr\">portfolio</code>.","why":"Correct. The <code dir=\"ltr\">.git</code> folder is the repository. Removing the stray one (it has no history you need) undoes the mistake completely."}],"answer":2},{"q":"<p>Which command makes every new repository on your machine start on a branch called <code dir=\"ltr\">main</code>?</p>","options":[{"text":"<code dir=\"ltr\">git config --global init.defaultBranch main</code>","why":"Correct. <code dir=\"ltr\">init.defaultBranch</code> sets the name of the first branch that <code dir=\"ltr\">git init</code> creates."},{"text":"<code dir=\"ltr\">git branch --default main</code>","why":"There’s no <code dir=\"ltr\">--default</code> option on <code dir=\"ltr\">git branch</code>. Default names come from configuration, not from a branch command."},{"text":"<code dir=\"ltr\">git config core.branch main</code>","why":"<code dir=\"ltr\">core.branch</code> isn’t a real setting, and without <code dir=\"ltr\">--global</code> it would only affect the current repository anyway."},{"text":"<code dir=\"ltr\">git init --main</code>","why":"<code dir=\"ltr\">git init</code> has <code dir=\"ltr\">-b &lt;name&gt;</code> (or <code dir=\"ltr\">--initial-branch</code>) for one repository, but no <code dir=\"ltr\">--main</code> flag, and it wouldn’t affect future repositories."}],"answer":0}],"exercise":{"kind":"fill","language":"bash","template":"git config --global user.email \"maya.okafor@example.com\"\ngit config --global {{0}} main\n\nmkdir portfolio && cd portfolio\ngit {{1}}\ngit add index.html\ngit commit {{2}} \"Add home page\"","blanks":[{"answers":["init.defaultBranch","init.defaultbranch"]},{"answers":["init"]},{"answers":["-m","--message"]}],"title":"Set up and commit the portfolio","prompt":"<p>Fill in the blanks so that every new repository starts on <code dir=\"ltr\">main</code>, the <code dir=\"ltr\">portfolio</code> folder becomes a repository, and the home page is committed with the message on the command line (no editor).</p>\n","hints":["The default branch name is a setting in the <code dir=\"ltr\">init</code> group of the configuration.","The command that creates the <code dir=\"ltr\">.git</code> folder has the same name as that setting group.","The flag that passes the commit message inline is a single letter, short for message."],"explanation":"<p><code dir=\"ltr\">git config --global init.defaultBranch main</code> makes <code dir=\"ltr\">git init</code> name its first branch <code dir=\"ltr\">main</code>. <code dir=\"ltr\">git init</code> creates the <code dir=\"ltr\">.git</code> folder that holds the repository. <code dir=\"ltr\">git commit -m &quot;Add home page&quot;</code> records the staged snapshot with the message inline; leave out <code dir=\"ltr\">-m</code> and Git opens <code dir=\"ltr\">core.editor</code> to ask for one.</p>\n","checkLabels":{}},"words":712,"readMinutes":3}