{"id":1346,"date":"2017-04-17T12:43:19","date_gmt":"2017-04-17T07:13:19","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1346"},"modified":"2017-04-17T12:43:19","modified_gmt":"2017-04-17T07:13:19","slug":"working-git-commands-repositories","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/working-git-commands-repositories\/","title":{"rendered":"Working with Git commands and Repositories"},"content":{"rendered":"<h4><strong>Working with Git<\/strong><\/h4>\n<p><strong>Date Posted:16-04-2017<\/strong><\/p>\n<p>Git is a version control system designed to handle small projects to large projects in a effective way. This post explains on how to use git commands and how to handle git repositories,etc.,<\/p>\n<h4>Git Repositories:<\/h4>\n<p>Git repositories are the location where you can store the all your project\/application code. It could be either on github account or your own private repositories such as gitlab or bitbucket account,etc.,<\/p>\n<h5>Clone repository:<\/h5>\n<p>Normally, there are two ways to clone the repositories. One is via http protocol or other way is to use SSH protocol.<\/p>\n<p>The below command is to clone the git repository to your local machine using https protocol.<\/p>\n<p><code>git clone https:\/\/gitrepourl\/repo.git<\/code><\/p>\n<p>This will create a directory called <em>repo<\/em> on your local machine.<\/p>\n<p>Incase, if we receive an error git command not found, we need to install git on the machine.<\/p>\n<p><code><\/code>For Ubuntu,<\/p>\n<p><code>apt-get install git<\/code><\/p>\n<p>For Centos,<\/p>\n<p><code>yum install git<\/code><\/p>\n<p>Now, we can setup git on the machine.<\/p>\n<p><code>git config --global user.name \"Your Name\"<\/code><\/p>\n<p><code>git config --global user.email \"your-username@domain.tld\"<\/code><\/p>\n<h5><code><\/code>Git Commands:<\/h5>\n<p>So far, we have cloned the repository and setup git. \u00a0Now, we are making changes the files and commit to the repository.<\/p>\n<p>We are creating a file test.html on your local machine and push it to git repository.<\/p>\n<p><code>vi test.html<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Test Content<\/pre>\n<p>Now, add the file to git repository<\/p>\n<p><code>git add test.html<\/code><\/p>\n<p>Commit the file with your changes.<\/p>\n<p><code>git commit -m \"Adding test.html\"<\/code><\/p>\n<p>Add remote\u00a0repository to origin.<\/p>\n<p><code>git remote add origin\u00a0https:\/\/gitrepourl\/repo.git<\/code><\/p>\n<p>Push the changes to the remote origin.<\/p>\n<p><code>git push origin master<\/code><\/p>\n<p>Where<\/p>\n<p>Origin is remote URL<\/p>\n<p>master is a local repository.<\/p>\n<h5>Additional Information:<\/h5>\n<p>The above example is a simple one which explains on how to push a single file to git repo. In this section, we will explain few more git command which can help on how to use git effectively.<\/p>\n<p>To show recent changes, current commits,etc.,<\/p>\n<p><code>git status<\/code><\/p>\n<p>To view the remote repository.<\/p>\n<p><code>git remote -v<\/code><\/p>\n<p>To view the git log and commit IDs.<\/p>\n<p><code>git log<\/code><\/p>\n<p>To stash all the local changes<\/p>\n<p><code>git stash<\/code><\/p>\n<p><code><\/code>To create a new branch from master<\/p>\n<p><code>git branch name-of-branch<\/code><\/p>\n<p>To checkout to another git branch.<\/p>\n<p><code>git checkout -b name-of-branch<\/code><\/p>\n<p>To merge a branch to master. First Checkout to master branch and merge the branch<\/p>\n<p><code>git checkout master<\/code><\/p>\n<p><code>git merge name-of-branch<\/code><\/p>\n<p>To delete a file from git branch. First delete the file, commit and push the file.<\/p>\n<p><code>git rm test.html<\/code><\/p>\n<p><code>git commit -m \"Delete from git\"<\/code><\/p>\n<p><code>git push origin master<\/code><\/p>\n<p>To move to previously saved git commit.<\/p>\n<p><code>git reset --hard HEAD~1<\/code><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working with Git Date Posted:16-04-2017 Git is a version control system designed to handle small projects to large projects in [&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":[283],"class_list":["post-1346","post","type-post","status-publish","format-standard","hentry","category-containers-kubernetes","tag-git","psol-cat-containers-kubernetes"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-lI","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1346","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=1346"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1346\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}