{"id":1346,"date":"2017-04-17T12:43:19","date_gmt":"2017-04-17T07:13:19","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1346"},"modified":"2026-09-28T20:35:52","modified_gmt":"2026-09-28T15:05:52","slug":"working-git-commands-repositories","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/working-git-commands-repositories\/","title":{"rendered":"Git Commands: A Beginner\u2019s Guide to Repository Management"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date<\/strong>: April 16, 2017<br><strong>Last Updated<\/strong>: September 28, 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 manage and track changes in source code and other project files. It allows developers to work collaboratively, maintain different versions of a project, create branches, and synchronize changes with remote repositories such as GitHub, GitLab, or Bitbucket.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains the basic Git commands required to clone a repository, configure Git, add and commit files, push changes to a remote repository, manage branches, view commit history, and perform other common Git operations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before working with Git, ensure that the following requirements are met:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Linux system with administrative or sudo access.<\/li>\n\n\n\n<li>Git should be installed on the system.<\/li>\n\n\n\n<li>Access to a Git repository hosted locally or on a remote Git service.<\/li>\n\n\n\n<li>Basic knowledge of Linux command-line operations.<\/li>\n\n\n\n<li>A configured Git username and email address.<\/li>\n\n\n\n<li>Appropriate permissions to access and push changes to the remote repository.<\/li>\n\n\n\n<li>For private repositories, the required authentication method, such as HTTPS credentials or SSH keys, should be configured.<\/li>\n<\/ul>\n\n\n<h2>Implementation<\/h2>\n<h3>Git Repositories:<\/h3>\n<p>Git repositories are the location where you can store all your project\/application code. It could be either on a GitHub account or in your own private repositories, such as a GitLab or Bitbucket account, etc.<\/p>\n<h3>Clone repository:<\/h3>\n<p>Normally, there are two ways to clone the repositories. One is via the HTTP protocol, and the other way is to use the SSH protocol.<\/p>\n<p>The command below is to clone the git repository to your local machine using the 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>In case 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 set up 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<h3><code><\/code>Git Commands:<\/h3>\n<p>So far, we have cloned the repository and set up Git. \u00a0Now, we are making changes to the files and committing to the repository.<\/p>\n<p>We are creating a file test.html on your local machine and pushing it to the 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 the 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 the remote repository as 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 the remote URL<\/p>\n<p>master is a local repository.<\/p>\n<h3>Additional Information:<\/h3>\n<p>The above example is a simple one that explains how to push a single file to a Git repo. In this section, we will explain a few more Git commands that can help you 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 check out to another git branch.<\/p>\n<p><code>git checkout -b name-of-branch<\/code><\/p>\n<p>To merge a branch into master. First, check out the 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 a 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 a previously saved git commit.<\/p>\n<p><code>git reset --hard HEAD~1<\/code><\/p>\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Git provides an efficient way to manage source code and track changes throughout the development lifecycle. Using commands such as <code>git clone<\/code>, <code>git add<\/code>, <code>git commit<\/code>, <code>git push<\/code>, <code>git status<\/code>, and <code>git branch<\/code>, developers can manage repositories and collaborate effectively.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The commands covered in this guide provide a foundation for working with Git repositories. As projects become more complex, additional Git features such as branching strategies, remote repository management, merging, rebasing, and conflict resolution can be used to manage development workflows more effectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. How do I clone a Git repository?<\/strong><br>You can clone a remote Git repository using the <code>git clone<\/code> command:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>git clone https:\/\/gitrepourl\/repo.git<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. How do I check the current status of a Git repository?<\/strong><br>Use the following command to view modified, staged, and untracked files:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>git status<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. How do I create and switch to a new Git branch?<\/strong><br>You can create and switch to a new branch using:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>git checkout -b name-of-branch<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This creates the branch and switches to it immediately.<\/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 fundamentals<\/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\u00a0web hosting, domain registration, DevOps and cloud, software development, web applications, mobile applications, and enterprise solutions. Get in touch with our team\u00a0<a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: April 16, 2017Last Updated: September 28, 2026 Introduction Git is a distributed version control system used to manage [&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":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1346\/revisions"}],"predecessor-version":[{"id":11991,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1346\/revisions\/11991"}],"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}]}}