{"id":2475,"date":"2018-09-21T09:30:44","date_gmt":"2018-09-21T04:00:44","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=2475"},"modified":"2026-09-24T16:51:07","modified_gmt":"2026-09-24T11:21:07","slug":"git-commands","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/git-commands\/","title":{"rendered":"Git Commands and Tutorials: A Beginner\u2019s Guide"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Post Date: September 21, 2018<br>Last Updated: September 24, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Git is a distributed version control system used to track changes in source code and manage software development projects efficiently. It allows developers to maintain different versions of files, collaborate with team members, and synchronize changes between local and remote repositories. This tutorial provides an overview of commonly used Git commands and explains the basic Git workflow, including creating or cloning repositories, staging changes, committing changes, viewing history, and working with remote repositories.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before following this tutorial, ensure that you have the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Basic knowledge of Linux command-line operations.<\/li>\n\n\n\n<li>A Linux-based system such as Debian\/Ubuntu or CentOS\/RHEL.<\/li>\n\n\n\n<li>Sufficient privileges to install software packages.<\/li>\n\n\n\n<li>Git installed on the system.<\/li>\n\n\n\n<li>Access to a Git repository for practicing clone, pull, push, fetch, and merge operations.<\/li>\n\n\n\n<li>Basic understanding of files, directories, and source-code management.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n<p><strong>Step 1:\u00a0<\/strong> Git Installation in Linux:<\/p>\n<p>For Debian Linux based environment use this command line.<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\u25cf apt-get install git <\/code><\/p>\n<p>For Centos based environment use this command line.<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\u25cf yum install git<\/code><\/p>\n<p><strong>Step 2:\u00a0<\/strong> Git Configuration:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-title=\"Git Configuration\"># git config --global user.name \"Name Surname\"<\/code><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-title=\"Git Configuration\"># git config --global user. Email name.surname@xyz.com<\/code><\/p>\n<p><strong>Step 3:<\/strong> Getting Git Repository:<\/p>\n<ul>\n<li style=\"text-align: left;\">To <strong>clone<\/strong> an existing repository from server 2:<\/li>\n<\/ul>\n<p style=\"text-align: left;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0If you want to get a copy of an existing Git repository, use git clone [URL].<\/p>\n<p style=\"text-align: left;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0git clone\u00a0user@server:\/path.git<\/p>\n<p style=\"text-align: left;\"><code class=\"EnlighterJSRAW\">\u00a0 # git clone username@\/10.1.1.1:\/usr\/local\/blog01.git<\/code><\/p>\n<ul>\n<li>To start tracking new\/edited filename(add single file at a time).<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\"># git add filename <\/code><\/p>\n<ul>\n<li>Let&#8217;s start tracking all changed\/new files(add multiple files at a time).<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\"># git add. (git add -A)<\/code><\/p>\n<ul>\n<li>\u00a0Save changes to the local repository.<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\"># git commit -m 'Commit message\u2019<\/code><\/p>\n<p><strong>Step 4:<\/strong> Recording changes to the repository:<\/p>\n<ul>\n<li><strong>status<\/strong><\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\"># git status<\/code><\/p>\n<p><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/status-1.png\"><img decoding=\"async\" class=\" wp-image-2488 alignleft\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/status-1.png\" alt=\"\" width=\"403\" height=\"84\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/status-1.png 532w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/status-1-300x63.png 300w\" sizes=\"(max-width: 403px) 100vw, 403px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/status-2.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-2490 alignleft\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/status-2.png\" alt=\"\" width=\"552\" height=\"159\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/status-2.png 946w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/status-2-300x87.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/status-2-768x222.png 768w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/><\/a><\/p>\n<p><strong>Step 5:<\/strong> Recording changes to the repository:<\/p>\n<ul>\n<li><strong>Tracking our files.<\/strong><\/li>\n<li>To Begin tracking a new file (directory).<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\"># git add <\/code><\/p>\n<p><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-1.0.png\"><img decoding=\"async\" class=\"alignnone wp-image-2491\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-1.0.png\" alt=\"\" width=\"212\" height=\"42\" \/><\/a><\/p>\n<p><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/addd1.o.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2493\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/addd1.o.png\" alt=\"\" width=\"407\" height=\"134\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/addd1.o.png 563w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/addd1.o-300x99.png 300w\" sizes=\"(max-width: 407px) 100vw, 407px\" \/><\/a><\/p>\n<p><strong>Step 6:<\/strong> Recording changes to the repository:<\/p>\n<ul>\n<li><strong>Staging modified files.<\/strong><\/li>\n<li>To Stage the file, add this content to the next commit.<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#git add <\/code><\/p>\n<p><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-2.0.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2496\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-2.0.png\" alt=\"\" width=\"567\" height=\"183\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-2.0.png 834w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-2.0-300x97.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-2.0-768x248.png 768w\" sizes=\"(max-width: 567px) 100vw, 567px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-2.1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2498\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-2.1.png\" alt=\"\" width=\"408\" height=\"171\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-2.1.png 594w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/add-2.1-300x126.png 300w\" sizes=\"(max-width: 408px) 100vw, 408px\" \/><\/a><\/p>\n<p><strong>Step 7:<\/strong> Viewing staged and unstaged changes:<\/p>\n<ul>\n<li>To view\u00a0what changes but not yet get staged ,So that diff command is used.<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#git diff <\/code><\/p>\n<p><strong>Step 8:<\/strong> Recording changes to the repository:<\/p>\n<ul>\n<li>To commit your changes to the local repository.<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\"># git commit <\/code><\/p>\n<p><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/commit-1.0.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2507\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/commit-1.0.png\" alt=\"\" width=\"425\" height=\"82\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/commit-1.0.png 549w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2018\/09\/commit-1.0-300x58.png 300w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/a><\/p>\n<p><strong>Step 9:\u00a0\u00a0<\/strong>To\u00a0Viewing the commit history:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\"># git log<\/code><\/p>\n<p><strong>Step 10:<\/strong> Working with remotes:<\/p>\n<ul>\n<li><strong>Fetch:<\/strong> To fetch all the information\u00a0 you don&#8217;t have from remote repository, no automatic merging occurs here.<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#git fetch <\/code><\/p>\n<ul>\n<li><strong>Merge:<\/strong> To\u00a0 automatically merge data from remote with your repository data.<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#git merge <\/code><\/p>\n<ul>\n<li><strong>Pull:<\/strong> To fetch and merge automatically.<\/li>\n<li>pull = fetch + merge<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#git pull<\/code><\/p>\n<ul>\n<li><strong>Push:<\/strong>To push your version to the server.<\/li>\n<\/ul>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">$ git push origin master <\/code><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Good Note:<\/strong><\/span><\/p>\n<p>Git <strong>won&#8217;t allow you to push to the remote<\/strong> that is ahead of your version:<\/p>\n<p>At first needed to <strong>fetch<\/strong>. Otherwise, show a error as follows,<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">![rejected]  master -&gt; master (non-fast-forward)<\/code><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">error: failed to push some refs to 'http:\/\/gituser\/XYZ.git'.<\/code><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hint: Updates were rejected because the tip of your current branch is behind<\/code><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')<br \/>\n<\/code><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hint: before pushing again.<\/code><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">hint: See the 'Note about fast-forwards' in 'git push --help' for details.<\/code><\/p>\n<div class=\"entry-inner\">\n<p>Now we have practised some basic git commands. We hope it will be useful for beginners. Write to us in the comment box for any suggestions. Thanks in advance.<\/p>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Git provides a simple and effective way to track changes, manage different versions of files, and collaborate with others. In this tutorial, we covered essential Git commands such as <code>git clone<\/code>, <code>git add<\/code>, <code>git commit<\/code>, <code>git status<\/code>, <code>git diff<\/code>, <code>git log<\/code>, <code>git fetch<\/code>, <code>git merge<\/code>, <code>git pull<\/code>, and <code>git push<\/code>. Understanding these fundamental commands and the Git workflow provides a strong foundation for working with Git repositories and managing development projects efficiently.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. What is Git?<\/strong><br>Git is a distributed version control system used to track changes in files, manage different versions of a project, and support collaboration between developers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. What are the three main states in Git?<\/strong><br>The three main states are <strong>Modified<\/strong>, <strong>Staged<\/strong>, and <strong>Committed<\/strong>. Modified files contain changes, staged files are prepared for the next commit, and committed changes are stored in the local Git repository.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. How do I install Git on Linux?<\/strong><br>On Debian\/Ubuntu-based systems, use <code>apt-get install git<\/code>. On CentOS\/RHEL-based systems, use <code>yum install git<\/code> or the appropriate package manager available on the system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/git-fundamentals\/\">Git Fundamental <\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for the right technology solution for your business?. Our experts can help with&nbsp;web hosting, domain registration, DevOps and cloud, software development, web applications, mobile applications, and enterprise solutions. Get in touch with our team&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: September 21, 2018Last Updated: September 24, 2026 Introduction Git is a distributed version control system used to track [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1020],"tags":[414],"class_list":["post-2475","post","type-post","status-publish","format-standard","hentry","category-containers-kubernetes","tag-git-commands","psol-cat-containers-kubernetes"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-DV","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2475"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2475\/revisions"}],"predecessor-version":[{"id":11918,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2475\/revisions\/11918"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}