To init git on my directory to pull project from git repository.
Tags: git, gitcommand, github
Published: 2024-03-12 08:11:31

<ol>
   <li>
      <p><strong>Install Git:</strong>
         Download and install Git from <a target="_new">Git Downloads</a>.
      </p>
   </li>
   <li>
      <p><strong>Navigate to Your Project Directory:</strong>
         Open a terminal or command prompt and run:
      </p>
      <pre><div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span class="" data-state="closed"></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash"><span class="hljs-built_in">cd</span> /path/to/your/directory
</code></div></div></pre>
   </li>
   <li>
      <p><strong>Initialize Git:</strong>
         Run:
      </p>
      <pre><div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span class="" data-state="closed"></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">git init
</code></div></div></pre>
   </li>
   <li>
      <p><strong>Configure Git:</strong>
         Replace "Your Name" and "<a target="_new">your.email@example.com</a>" with your details:
      </p>
      <pre><div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span class="" data-state="closed"></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">git config --global user.name <span class="hljs-string">"Your Name"</span>
git config --global user.email <span class="hljs-string">"your.email@example.com"</span>
</code></div></div></pre>
   </li>
   <li>
      <p><strong>Add GitLab Repository as Remote:</strong>
         Replace <code>&lt;repository_url&gt;</code> with the actual URL:
      </p>
      <pre><div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span class="" data-state="closed"></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">git remote add origin &lt;repository_url&gt;
</code></div></div></pre>
<p>If you need to edit:</p>
<pre><div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span class="" data-state="closed"></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">git remote set-url origin &lt;repository_url&gt;</code></div></div></pre>
   </li>
   <li>
      <p><strong>Pull from GitLab:</strong>
         Replace "master" with the branch name if needed:
      </p>
      <pre><div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span class="" data-state="closed"></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">git pull origin master
</code></div></div></pre>
      <p>For private repositories, Git may prompt for your GitLab username and password.</p>
   </li>
   <li>
      <p><strong>Optional: Check Remote Configuration:</strong>
         Run:
      </p>
      <pre><div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span class="" data-state="closed"></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-bash">git remote -v
</code></div></div></pre>
      <p>Verify that it shows the URL of your GitLab repository.</p>
   </li>
</ol>