{"id":2475,"date":"2018-09-21T09:30:44","date_gmt":"2018-09-21T04:00:44","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=2475"},"modified":"2018-10-12T15:52:19","modified_gmt":"2018-10-12T10:22:19","slug":"git-commands","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/git-commands\/","title":{"rendered":"Git Commands and Tutorials"},"content":{"rendered":"<h3>Git Commands and Tutorials<\/h3>\n<h4>Date posted : 21.09.2018<\/h4>\n<p>In this article we learn about the overview of git commands and step by step tutorials.<\/p>\n<p><strong><span style=\"text-decoration: underline\">Basic Git Tutorial:<\/span><\/strong><\/p>\n<p>This tutorial provides a list of the most common GIT commands and a short description to explore lot in it.<\/p>\n<p><span style=\"text-decoration: underline\"><strong>Git at three States:<\/strong><\/span><\/p>\n<ul>\n<li>Commited (stored in local database).<\/li>\n<li>Modified (file changed but not commited to database).<\/li>\n<li>Staged (modified file is marked to go into the next commit snapshot).<\/li>\n<\/ul>\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> 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>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/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>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/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 to push to the remote<\/strong> which is ahead of your version:<\/p>\n<p>At first needed to be<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>&nbsp;<\/p>\n<p>Still now we have practiced some basic git commands.We hope it will be useful for the Beginners. Write\u00a0 us in the comment box for any suggestions. Thanks in advance.<\/p>\n<\/div>\n<div class=\"sharrre-container\"><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git Commands and Tutorials Date posted : 21.09.2018 In this article we learn about the overview of git commands and [&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_feature_clip_id":0,"_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":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2475\/revisions"}],"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}]}}