{"id":11064,"date":"2025-09-02T09:05:05","date_gmt":"2025-09-02T09:05:05","guid":{"rendered":"https:\/\/www.ssdnodes.com\/?p=11064"},"modified":"2025-09-02T10:44:51","modified_gmt":"2025-09-02T10:44:51","slug":"install-git-on-debian-12","status":"publish","type":"post","link":"https:\/\/www.ssdnodes.com\/blog\/install-git-on-debian-12\/","title":{"rendered":"Full Guide: How To Install Git on Debian 12 and Use it"},"content":{"rendered":"<p>Looking for a detailed guide on how to install Git on Debian 12 and use it for version control on your server? This is the article you\u2019ve been looking for.<\/p>\n<p>Git and version control is probably the most important part of software development these days, and Debian is one of the most widely used operating systems among <a href=\"https:\/\/www.ssdnodes.com\/blog\/best-vps-hosting-for-developers\/\">developers<\/a>. No matter your current expertise level in software development, learning to use Git is extremely important for good collaboration and project management.<\/p>\n<p>In this guide, I'll walk you through the process of installing and configuring Git on Debian 12 in a few steps.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11120 size-full\" style=\"border-radius: 25px;\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/How-To-Install-Git-on-Debian-12-and-Use-it-Blog-1.png\" alt=\"Install Git on Debian 12\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/How-To-Install-Git-on-Debian-12-and-Use-it-Blog-1.png 600w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/How-To-Install-Git-on-Debian-12-and-Use-it-Blog-1-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2>Prerequisites<\/h2>\n<p>Before you install Git, you need:<\/p>\n<ul>\n<li>A Debian 12 server. Get your VPS hosting from a reputable and trustworthy provider like <strong>SSD Nodes<\/strong>. We offer powerful Debian servers and the best deals. Take a look at our <a href=\"https:\/\/ssdnodes.com\/\" target=\"_blank\" rel=\"noopener\">offerings<\/a> and prepare for your mind to be blown \ud83e\udd2f.<\/li>\n<\/ul>\n<p>Check out our <a href=\"https:\/\/www.ssdnodes.com\/blog\/tutorial-setting-up-and-securing-ssh-based-authentication\/\">How to access your server using SSH<\/a> guide to learn how to access your server and create a <code>sudo<\/code> user.<\/p>\n<h2>Step 1: Updating the System Package List<\/h2>\n<p>Start by updating the packages in the package manager cache to the latest available versions using the following command:<\/p>\n<pre><code>sudo apt update<\/code><\/pre>\n<h2>Step 2: Install Git on Debian 12<\/h2>\n<p>Debian offers two primary ways to install Git:<\/p>\n<ol>\n<li>Through the APT package manager, which is simpler and faster.<\/li>\n<li>Compiling Git from source (which provides more control over the version you install). We'll cover both methods below.<\/li>\n<\/ol>\n<h3><strong>Install Git Using APT<\/strong><\/h3>\n<p>The easiest way to install Git on Debian 12 is by using the APT package manager. This method installs a stable version of Git directly from Debian\u2019s official repositories. Here\u2019s how to do it:<\/p>\n<pre><code class=\"language-bash\">sudo apt install git<\/code><\/pre>\n<p>Once the installation is complete, you can verify the version of Git installed by running:<\/p>\n<pre><code class=\"language-bash\">git --version<\/code><\/pre>\n<p>Output:<\/p>\n<pre><code class=\"language-bash\">git version 2.39.5<\/code><\/pre>\n<p>At this point, Git should be ready for use. However, if you need a more up-to-date version, you can install Git from source. To do this, follow the instructions outlined in the next section.<\/p>\n<h3><strong>Install Git From Source<\/strong><\/h3>\n<p>If you need the latest version of Git or want to customize the installation, you can compile Git from source. This method requires a few additional steps, but it allows for greater flexibility.<\/p>\n<p>First, install the necessary dependencies:<\/p>\n<pre><code class=\"language-bash\">sudo apt install wget dh-autoreconf libcurl4-gnutls-dev libexpat1-dev \\\r\n  gettext libz-dev libssl-dev asciidoc xmlto docbook2x install-info build-essential<\/code><\/pre>\n<p>Next, download the latest Git source code. Visit the\u00a0<a href=\"https:\/\/git-scm.com\/downloads\/linux\" target=\"_blank\" rel=\"noopener\">Git release page<\/a>\u00a0and find the latest version:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11069\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/git-version-1024x518.webp\" alt=\"Git latest version\" width=\"800\" height=\"405\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/git-version-1024x518.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/git-version-300x152.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/git-version-768x388.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/git-version.webp 1475w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Next, use the following command to download and extract it (replace\u00a0<code>2.47.0<\/code>\u00a0with the latest version number):<\/p>\n<pre>\u2022 wget https:\/\/www.kernel.org\/pub\/software\/scm\/git\/git-2.47.0.tar.gz<\/pre>\n<pre>tar -zxf git-2.47.0.tar.gz<\/pre>\n<pre>cd git-2.47.0<\/pre>\n<p>Now, generate the configuration script for Git:<\/p>\n<pre><code class=\"language-bash\">make configure<\/code><\/pre>\n<p>Output:<\/p>\n<pre><code class=\"language-bash\">GIT_VERSION = 2.47.0\r\n    GEN configure<\/code><\/pre>\n<p>Run this configuration script, specifying that the Git binaries should be installed under the <code>\/usr<\/code> directory:<\/p>\n<pre><code class=\"language-bash\">.\/configure --prefix=\/usr<\/code><\/pre>\n<p>The output will inform you that the checks are done and the configuration files are created:<\/p>\n<pre><code class=\"language-bash\">configure: creating .\/config.status\r\nconfig.status: creating config.mak.autogen\r\nconfig.status: executing config.mak.autogen commands<\/code><\/pre>\n<p>Compile Git and build the documentation:<\/p>\n<pre><code class=\"language-bash\">make all doc info<\/code><\/pre>\n<p>Finally, install Git, along with its documentation:<\/p>\n<pre><code class=\"language-bash\">sudo make install install-doc install-html install-info<\/code><\/pre>\n<p>Verify that Git was installed successfully:<\/p>\n<pre><code class=\"language-bash\">git --version<\/code><\/pre>\n<p>You should see a version that matches the tarball you\u2019ve downloaded:<\/p>\n<pre><code class=\"language-bash\">git version 2.47.0<\/code><\/pre>\n<h2>Step 3: Configuring Git<\/h2>\n<p>Once Git is installed on your Debian 12 server, the next step is to configure it. This is important because Git needs to associate your commits with your identity. Run the following commands to set up your name and email address:<\/p>\n<pre><code class=\"language-bash\">git config --global user.name \"Your Name\"\r\ngit config --global user.email \"youremail@example.com\"<\/code><\/pre>\n<p>These settings will be used in every Git commit you make, so make sure they are accurate. You can verify the configuration at any time by running:<\/p>\n<pre><code class=\"language-bash\">git config --list<\/code><\/pre>\n<h2>Step 4: Using Git<\/h2>\n<p>Now that Git is installed and configured, it\u2019s time to start using it. Below, we\u2019ll cover some of the most common tasks you'll perform with Git, such as cloning and creating repositories, staging and committing changes, and also managing branches.<\/p>\n<h3>Cloning an Existing Repository<\/h3>\n<p>If you want to work on an existing project, you can clone its repository. Cloning creates a local copy of the remote repository on your machine, similar to downloading a directory with its files from the web.<\/p>\n<p>To clone a repository, use:<\/p>\n<pre><code class=\"language-bash\">git clone https:\/\/github.com\/user\/repo.git<\/code><\/pre>\n<p>This command downloads the entire repository, including its history.<\/p>\n<h3>Create a New Repository<\/h3>\n<p>To demonstrate how to use git in a project, create a new directory and navigate to it:<\/p>\n<pre><code class=\"language-bash\">mkdir myproject\r\ncd myproject<\/code><\/pre>\n<p>Then, run the following command to mark this <code>myproject<\/code> directory as a Git repository:<\/p>\n<pre><code class=\"language-bash\">git init<\/code><\/pre>\n<p>This will create a hidden <code>.git<\/code> directory, which Git uses to track changes in your project. From here, you can start adding files and making commits.<\/p>\n<h3>Git Staging<\/h3>\n<p>Before committing changes, you need to stage them. Staging allows you to choose which changes should be part of the next commit.<\/p>\n<p>Changes can be in the form of new files, or modifications to existing files.<\/p>\n<p>For example, let\u2019s add a new file called <code>index.html<\/code> to your project:<\/p>\n<pre><code class=\"language-bash\">touch index.html<\/code><\/pre>\n<p>Use <code>git status<\/code> to check the status of your Git repository:<\/p>\n<pre><code class=\"language-bash\">git status<\/code><\/pre>\n<p>The output will be similar to the following:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11070\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/Git-Status-1024x271.webp\" alt=\"Git status\" width=\"600\" height=\"159\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/Git-Status-1024x271.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/Git-Status-300x80.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/Git-Status-768x204.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/Git-Status-1536x407.webp 1536w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/Git-Status.webp 2000w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>This informs you that there is an untracked file called <code>index.html<\/code> with a helpful message telling you how to make it trackable.<\/p>\n<p>To add this new <code>index.html<\/code> to the Git repository and make it trackable, use the <code>git add<\/code> command:<\/p>\n<pre><code class=\"language-bash\">git add index.html<\/code><\/pre>\n<p>This adds the new file to the staging area, meaning Git is now tracking it and will include it in the next commit.<\/p>\n<p>Check <code>git status<\/code> again:<\/p>\n<pre><code class=\"language-bash\">On branch master\r\n\r\nNo commits yet\r\n\r\nChanges to be committed:\r\n  (use \"git rm --cached &lt;file&gt;...\" to unstage)\r\n    new file:   index.html<\/code><\/pre>\n<p>You can also stage all new files and modifications at once by using:<\/p>\n<pre><code class=\"language-bash\">git add .<\/code><\/pre>\n<p>This command adds all modified and untracked files to staging, preparing them for the next commit.<\/p>\n<h3>Committing Changes<\/h3>\n<p>Once your changes are staged, the next step is to commit them. Commits are snapshots of your project at a given point in time. To commit your staged changes, run:<\/p>\n<pre><code class=\"language-bash\">git commit -m \"Describe your changes here\"<\/code><\/pre>\n<p>Make sure your commit message is clear and actually describes what the new code does.<\/p>\n<h3>Adding a Github Remote Repository and Pushing Changes<\/h3>\n<p>To collaborate on a project hosted on the web, such as projects on <a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noopener\">GitHub<\/a>, you first need to add a remote repository after initializing your local Git repository.<\/p>\n<p>The first step is to create a repository on GitHub. Go to the\u00a0<a href=\"https:\/\/github.com\/new\" target=\"_blank\" rel=\"noopener\">Create a New Repository<\/a>\u00a0page, and create a repository.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11071\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-new-repo.webp\" alt=\"Github New Repository\" width=\"740\" height=\"690\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-new-repo.webp 740w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-new-repo-300x280.webp 300w\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" \/><\/p>\n<p>Once the repository is created, copy the repository URL and use it to add a remote repository to your local Git repository:<\/p>\n<pre><code class=\"language-bash\">git remote add origin &lt;repository-url&gt;<\/code><\/pre>\n<p>This command sets up the connection between your local repository and the remote one.<\/p>\n<p>You can check if the remote repository was added successfully by running:<\/p>\n<pre><code class=\"language-bash\">git remote -v<\/code><\/pre>\n<p>Once you've added the remote repository and committed your changes, you can push them to the remote branch using <code>git push<\/code>:<\/p>\n<pre><code class=\"language-bash\">git push -u origin main<\/code><\/pre>\n<p>This command pushes your commits to the <code>main<\/code> branch of the remote repository. If you're working on a different branch, replace <code>main<\/code> with the correct branch name, you may need to replace it with <code>master<\/code> in certain cases.<\/p>\n<p>If you\u2019re using Github, Git will ask for your GitHub username and password. Type in your username and enter your personal access token for the password.<\/p>\n<p>To create a personal token on Github, navigate to the <a href=\"https:\/\/github.com\/settings\/tokens\/new\" target=\"_blank\" rel=\"noopener\">New personal access token<\/a> page. Select the scopes that you want to control, and then click Generate Token.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11072\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-access-token-1024x642.webp\" alt=\"Github Access Token\" width=\"740\" height=\"464\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-access-token-1024x642.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-access-token-300x188.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-access-token-768x481.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-access-token.webp 1154w\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" \/><\/p>\n<p>You\u2019ll be redirected to a page with your new token.<\/p>\n<p>For more information, check out <a href=\"https:\/\/docs.github.com\/en\/authentication\/keeping-your-account-and-data-secure\/managing-your-personal-access-tokens#about-personal-access-tokens\" target=\"_blank\" rel=\"noopener\">Managing your personal access tokens<\/a>.<\/p>\n<p>After using your personal access token as a password. The <code>git push -u origin main<\/code> command will give you the following output:<\/p>\n<pre><code class=\"language-bash\">Enumerating objects: 3, done.\r\nCounting objects: 100% (3\/3), done.\r\nWriting objects: 100% (3\/3), 215 bytes | 215.00 KiB\/s, done.\r\nTotal 3 (delta 0), reused 0 (delta 0), pack-reused 0\r\nTo https:\/\/github.com\/user\/repo\r\n * [new branch]      main -&gt; main\r\nbranch 'main' set up to track 'origin\/main'.<\/code><\/pre>\n<p>Your Github repository will then host your code:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11073\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-repo-pushed.webp\" alt=\"git push -u origin main\" width=\"740\" height=\"403\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-repo-pushed.webp 907w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-repo-pushed-300x163.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2024\/11\/github-repo-pushed-768x418.webp 768w\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" \/><\/p>\n<h3>Git Branching<\/h3>\n<p>Git makes it easy to work on different features or fixes in isolation using branches. To create a new branch, run:<\/p>\n<pre><code class=\"language-bash\">git branch &lt;branch-name&gt;<\/code><\/pre>\n<p>Then, switch to that branch with:<\/p>\n<pre><code class=\"language-bash\">git checkout &lt;branch-name&gt;<\/code><\/pre>\n<p>This allows you to work on a separate branch without affecting the main project. Once your changes are ready, you can merge the branch back into the <code>main<\/code> branch. For more on branches, check out <a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Git-Branching-Basic-Branching-and-Merging\" target=\"_blank\" rel=\"noopener\">this page<\/a>.<\/p>\n<h3>Undoing Changes<\/h3>\n<p>Mistakes happen, but don\u2019t worry! Git gives you great tools to undo errors. If you want to undo changes that haven\u2019t been committed yet, use:<\/p>\n<pre><code class=\"language-bash\">git checkout -- &lt;filename&gt;<\/code><\/pre>\n<p>This will revert the specified file to the last committed state. If you need to undo a commit, you can use:<\/p>\n<pre><code class=\"language-bash\">git reset --soft HEAD^<\/code><\/pre>\n<p>This undoes the last commit but leaves your changes in the staging area, allowing you to re-commit them after making adjustments.<\/p>\n<p>For more on undoing changes with Git, check out: <a href=\"https:\/\/github.blog\/open-source\/git\/how-to-undo-almost-anything-with-git\/\" target=\"_blank\" rel=\"noopener\">How to Undo Anything with Git<\/a><\/p>\n<h2>Step 6: Troubleshooting Common Git Issues<\/h2>\n<p>Sometimes, you might encounter issues while using Git. Here are some common problems and how to solve them:<\/p>\n<ul>\n<li><strong>\u201cCommand not found\u201d Error<\/strong>: If you receive a \u201cgit: command not found\u201d error, it means Git isn\u2019t installed or isn\u2019t in your system\u2019s PATH. Verify the installation and check your environment variables.<\/li>\n<li><strong>Permission Denied (Public Key)<\/strong>: This error often occurs when pushing or pulling from a remote repository like GitHub. It usually means your SSH keys aren\u2019t configured correctly. To fix this, generate a new SSH key using <code>ssh-keygen<\/code> and add it to your GitHub account.<\/li>\n<li><strong>Merge Conflicts<\/strong>: Merge conflicts happen when Git can\u2019t automatically merge two branches because of conflicting changes. You\u2019ll need to manually resolve the conflict by editing the files and then marking them as resolved using:\n<pre><code class=\"language-bash\">git add \r\n<\/code><\/pre>\n<p>After resolving the conflict, you can commit the changes.<\/li>\n<li><strong>Detached HEAD State<\/strong>: If you find yourself in a detached HEAD state, it means you\u2019re not on a branch, but rather on a specific commit. To fix this, switch back to your branch with:\n<pre><code class=\"language-bash\">git checkout main<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>These common issues are easy to fix once you understand the root cause, so don\u2019t be discouraged if you encounter them!<\/p>\n<h2>Conclusion<\/h2>\n<p>By following this guide, you should now have a fully functional Git setup on your Debian 12 system. You've learned how to install Git, configure it, and perform essential tasks such as creating repositories, cloning, committing changes, and working with branches. We've also covered how to connect your local repository to GitHub for easy collaboration and remote backups.<\/p>\n<p>Git is a powerful tool that can make managing your code much more efficient, whether you're working solo or with a team. Don\u2019t hesitate to explore Git\u2019s vast array of features as you grow more comfortable with it. And if you run into any issues, you now have some troubleshooting steps to guide you.<\/p>\n<h2>FAQ<\/h2>\n<h3>How do I upgrade Git to the latest version on Debian 12?<\/h3>\n<p>To upgrade Git to the latest version on Debian 12, first check if a newer version is available through the APT package manager by running <code>sudo apt update<\/code> and <code>sudo apt upgrade git<\/code>. If no newer version is available, you can download and compile the latest Git version from source to manually update it as I\u2019ve already explained in this tutorial.<\/p>\n<h3>How do I uninstall Git from Debian 12?<\/h3>\n<p>To uninstall Git from Debian 12, you can use the following command: <code>sudo apt remove git<\/code>. This will remove the Git package from your system. If you also want to remove configuration files and dependencies no longer needed, you can run <code>sudo apt autoremove<\/code>.<\/p>\n<h3>How do I configure Git to ignore specific files on Debian 12?<\/h3>\n<p>To configure Git to ignore specific files or directories in a repository on Debian 12, create a <code>.gitignore<\/code> file in the root of your repository. Inside this file, list the names of files or directories you want Git to ignore. For example, you can add <code>*.log<\/code> to ignore all log files or <code>node_modules\/<\/code> to ignore the <code>node_modules<\/code> directory.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to install and configure Git on Debian 12 like a pro. From installation to advanced troubleshooting, this guide has got you covered!<\/p>\n","protected":false},"author":19,"featured_media":11117,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[18,30],"tags":[],"class_list":["post-11064","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-tutorials"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/11064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/comments?post=11064"}],"version-history":[{"count":12,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/11064\/revisions"}],"predecessor-version":[{"id":13727,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/11064\/revisions\/13727"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media\/11117"}],"wp:attachment":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media?parent=11064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/categories?post=11064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/tags?post=11064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}