{"id":932,"date":"2022-06-02T14:40:44","date_gmt":"2022-06-02T14:40:44","guid":{"rendered":"https:\/\/www.checkmateq.com\/blog\/?p=932"},"modified":"2023-08-07T09:02:40","modified_gmt":"2023-08-07T09:02:40","slug":"basic-git-commands","status":"publish","type":"post","link":"https:\/\/www.checkmateq.com\/blog\/basic-git-commands","title":{"rendered":"Git commands and their usecase"},"content":{"rendered":"<p><strong>Git<\/strong> is open-source <strong>version control<\/strong> and <strong>source code management<\/strong> tool which allows us to efficiently track and manage code changes. Git is also key element in CICD pipeline automation for <a href=\"https:\/\/www.checkmateq.com\/devops-engineering\">DevOps management<\/a>.<\/p>\n<p>Following are some basic commands to perform git operations from the terminal.<\/p>\n<h3>Important git commands<\/h3>\n<ul>\n<li><strong>How to install git.<\/strong><\/li>\n<\/ul>\n<pre>sudo yum install git\r\n<\/pre>\n<ul>\n<li><strong>To check if git is installed, use the command below.<\/strong><\/li>\n<\/ul>\n<pre>git --version\r\n<img loading=\"lazy\" class=\"alignnone wp-image-1072\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-113909-300x23.png\" alt=\"\" width=\"743\" height=\"57\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-113909-300x23.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-113909-768x58.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-113909.png 996w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/>\r\n<\/pre>\n<ul>\n<li><strong>To initialize git, go to your code&#8217;s directory and use the command below.<\/strong><\/li>\n<\/ul>\n<pre>git init\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1071\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-111915-1-300x79.png\" alt=\"git\" width=\"737\" height=\"194\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-111915-1-300x79.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-111915-1-1024x269.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-111915-1-768x202.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-111915-1-1200x315.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-111915-1.png 1215w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>Use the command below to configure git with your information for a git commit message<\/strong>.<\/li>\n<\/ul>\n<pre>git config <span class=\"nt\">--global<\/span> user.name <span class=\"s2\">\"your_username\"<\/span>\r\n<span class=\"token function\">git<\/span> config --global user.email <span class=\"token string\">\"your_email@example.com\"\r\n<\/span><\/pre>\n<ul>\n<li><strong>For getting the status of our working directory and staging area use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git status\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1074\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-115026-300x77.png\" alt=\"git\" width=\"732\" height=\"188\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-115026-300x77.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-115026-1024x262.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-115026-768x197.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-115026-1536x394.png 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-115026-1200x307.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-115026.png 1573w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>Use the command below to add the file to the staging or index area.<\/strong><\/li>\n<\/ul>\n<pre>git add 'filename'\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1081\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-120520-300x126.png\" alt=\"git\" width=\"738\" height=\"310\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-120520-300x126.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-120520-1024x430.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-120520-768x323.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-120520.png 1174w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li>With the git status command, we can see that the backup.py file has been added to the staging area while the script.py file is still untracked. To add it use the same command. To add all the files in a directory to the staging area at once use the following command.<\/li>\n<\/ul>\n<pre>git add .\r\n<\/pre>\n<ul>\n<li><strong>Use the following command to commit changes.<\/strong><\/li>\n<\/ul>\n<pre>git commit -m \"commit message\"\r\n<img loading=\"lazy\" class=\"alignnone wp-image-1087\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-124051-300x65.png\" alt=\"git\" width=\"766\" height=\"166\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-124051-300x65.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-124051-1024x222.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-124051-768x167.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-124051-1200x260.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-124051.png 1222w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/>\r\n<\/pre>\n<ul>\n<li><strong>Use the following command to update the last commit message. An edit window will open, edit your message and save it<\/strong>.<\/li>\n<\/ul>\n<pre>git commit --amend\r\n<img loading=\"lazy\" class=\"alignnone wp-image-1089\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130428-300x130.png\" alt=\"git\" width=\"743\" height=\"322\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130428-300x130.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130428-1024x443.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130428-768x332.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130428.png 1117w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/>\r\n<\/pre>\n<ul>\n<li><strong>To see commits done in the current branch use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git log\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1090\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130522-300x49.png\" alt=\"git\" width=\"747\" height=\"122\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130522-300x49.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130522-1024x167.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130522-768x125.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130522-1200x196.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-130522.png 1218w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>Use the stat option with git log to get a\u00a0 summary of what was done to the committed files.<\/strong><\/li>\n<\/ul>\n<pre>git log --stat\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1092\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132317-300x146.png\" alt=\"git\" width=\"738\" height=\"359\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132317-300x146.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132317-1024x499.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132317-768x374.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132317.png 1072w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To see which branch you are on, use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git branch\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1095\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132545-300x22.png\" alt=\"\" width=\"736\" height=\"54\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132545-300x22.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132545-1024x76.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132545-768x57.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-132545.png 1108w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To create a new branch use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git branch 'branch name'\r\n<\/pre>\n<ul>\n<li><strong>To list all branches use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git branch -a\r\n<\/pre>\n<ul>\n<li><strong>To go to another branch use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git checkout 'branchname'\r\n<img loading=\"lazy\" class=\"alignnone wp-image-1097\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141318-300x40.png\" alt=\"git\" width=\"743\" height=\"99\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141318-300x40.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141318-1024x137.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141318-768x102.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141318-1200x160.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141318.png 1537w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/>\r\n<img loading=\"lazy\" class=\"alignnone wp-image-1098\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141426-300x26.png\" alt=\"\" width=\"738\" height=\"64\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141426-300x26.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141426-1024x90.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141426-768x67.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141426-1200x105.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141426.png 1212w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/>\r\n<\/pre>\n<ul>\n<li><strong>To create a new branch from the parent branch you are currently working on with all changes from the parent branch use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git checkout -b 'branch name'\r\n<img loading=\"lazy\" class=\"alignnone wp-image-1101\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141911-300x50.png\" alt=\"\" width=\"744\" height=\"124\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141911-300x50.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141911-1024x171.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141911-768x129.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141911-1200x201.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-141911.png 1207w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/pre>\n<ul>\n<li><strong><span class=\" jss1638 jss1639\"><span id=\"editable-content-within-article~0~0~0\" class=\"jss1640 jss1641\">For integrating different branches into a single branch use following command.<\/span><\/span><\/strong><\/li>\n<\/ul>\n<pre>git merge 'branch you want to merge'\r\n<\/pre>\n<p>We have made changes in the dev branch and now want to integrate them into the main branch. So first we will checkout to the master branch and then use git merge.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1109\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-154217-300x169.png\" alt=\"\" width=\"744\" height=\"419\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-154217-300x169.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-154217-1024x576.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-154217-768x432.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-154217.png 1030w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1112\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-155417-300x119.png\" alt=\"\" width=\"736\" height=\"292\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-155417-300x119.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-155417-1024x406.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-155417-768x304.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-155417.png 1173w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To delete a branch, use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git branch -d 'branch name'\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1155\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-07-015224-300x24.png\" alt=\"\" width=\"750\" height=\"60\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-07-015224-300x24.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-07-015224-768x62.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-07-015224.png 949w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To add a remote repository, use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git remote add origin 'repository url'\r\n<\/pre>\n<ul>\n<li><strong>Use the following command to push code to a remote repository in the master branch. Enter username and auth token when prompted.<\/strong><\/li>\n<\/ul>\n<pre id=\"empty-setup-push-repo-echo\" class=\"copyable-terminal-content f5\"><span class=\"user-select-contain\">git branch -M master<\/span>\r\n<span class=\"user-select-contain\">git push -u origin master\r\n\r\n<\/span><\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1114\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160015-300x90.png\" alt=\"\" width=\"743\" height=\"223\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160015-300x90.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160015-1024x309.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160015-768x231.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160015-1200x362.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160015.png 1228w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To clone a remote repository use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git clone 'repository url'\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1117\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160855-300x64.png\" alt=\"\" width=\"745\" height=\"159\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160855-300x64.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160855-1024x220.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160855-768x165.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160855-1200x258.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-160855.png 1261w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To get the latest changes from the remote repo use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git fetch origin\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1119\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161329-300x73.png\" alt=\"\" width=\"740\" height=\"180\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161329-300x73.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161329-768x187.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161329.png 874w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1120\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161539-300x35.png\" alt=\"\" width=\"737\" height=\"86\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161539-300x35.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161539-1024x120.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161539-768x90.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161539.png 1105w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To get the latest changes and integrate them into your working branch, use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git pull origin\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1121\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161642-300x57.png\" alt=\"\" width=\"742\" height=\"141\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161642-300x57.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161642-768x146.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-161642.png 793w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To save uncommitted changes into a stack, use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git stash save 'message'\r\n<\/pre>\n<p>Here we have added line in our code but we don&#8217;t want to commit it and want to switch branch, in that case git stash is very useful.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1123\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164121-300x67.png\" alt=\"\" width=\"739\" height=\"165\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164121-300x67.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164121-1024x229.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164121-768x172.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164121.png 1051w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1125\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164436-300x42.png\" alt=\"\" width=\"743\" height=\"104\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164436-300x42.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164436-1024x144.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164436-768x108.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164436.png 1117w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>Use the following command to list stash stack.<\/strong><\/li>\n<\/ul>\n<pre>git stash list\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1126\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164353-300x23.png\" alt=\"\" width=\"743\" height=\"57\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164353-300x23.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164353-768x60.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164353.png 820w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To bring back uncommitted changes saved at top of the stash stack use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git stash pop\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1127\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164621-300x97.png\" alt=\"git\" width=\"748\" height=\"242\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164621-300x97.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164621-768x250.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-164621.png 877w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>Use the following command to reset a branch to the local committed code and remove all uncommitted modifications. It reset the head, working area, and staging area.<\/strong><\/li>\n<\/ul>\n<pre>git reset --hard HEAD\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1138\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173057-300x94.png\" alt=\"git\" width=\"718\" height=\"225\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173057-300x94.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173057-1024x322.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173057-768x241.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173057.png 1051w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1137\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172925-300x84.png\" alt=\"\" width=\"729\" height=\"204\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172925-300x84.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172925-1024x287.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172925-768x215.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172925-1200x337.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172925.png 1255w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>Use the following command if you want to only reset the staging area and Head and not the working area.<\/strong><\/li>\n<\/ul>\n<pre>git reset --mixed HEAD\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1130\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-170651-300x179.png\" alt=\"git\" width=\"726\" height=\"433\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-170651-300x179.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-170651-1024x610.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-170651-768x458.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-170651.png 1072w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>Use the following command if you want to only reset head.<\/strong><\/li>\n<\/ul>\n<pre>git reset --soft HEAD\r\n<\/pre>\n<p>We have our head pointing to 976e95. We will use git reset and move head to point to ba605 but our changes will still be in the staging area.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1133\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172016-300x56.png\" alt=\"git\" width=\"729\" height=\"136\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172016-300x56.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172016-768x144.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172016.png 855w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1131\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-171545-300x49.png\" alt=\"\" width=\"710\" height=\"116\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-171545-300x49.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-171545-1024x167.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-171545-768x125.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-171545-1200x196.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-171545.png 1213w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1135\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172635-300x93.png\" alt=\"git\" width=\"729\" height=\"226\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172635-300x93.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-172635.png 742w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>To list the changes between the staging area and the current working directory use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git diff\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1140\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173455-300x150.png\" alt=\"git\" width=\"742\" height=\"371\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173455-300x150.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173455-768x384.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173455.png 817w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li><strong>To revert the committed changes and create a new commit with reversed content use the following command.<\/strong><\/li>\n<\/ul>\n<pre>git revert HEAD\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1141\" src=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173805-300x104.png\" alt=\"git\" width=\"747\" height=\"259\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173805-300x104.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173805-1024x356.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173805-768x267.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-06-173805.png 1116w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><a href=\"https:\/\/www.checkmateq.com\/\">Please contact<\/a> our technical consultants if you have anything related to source code management or <a href=\"https:\/\/www.checkmateq.com\/devops-engineering\">DevOps<\/a> pipeline automation to be discussed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git is open-source version control and source code management tool which allows us to efficiently track and manage code changes. Git is also key element in CICD pipeline automation for DevOps management. Following are some basic commands to perform git operations from the terminal. Important git commands How to install git. sudo yum install git &hellip; <a href=\"https:\/\/www.checkmateq.com\/blog\/basic-git-commands\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Git commands and their usecase&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":988,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[15,3,2,8,14,6],"_links":{"self":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/932"}],"collection":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/comments?post=932"}],"version-history":[{"count":89,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/932\/revisions"}],"predecessor-version":[{"id":4328,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/932\/revisions\/4328"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media\/988"}],"wp:attachment":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media?parent=932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/categories?post=932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/tags?post=932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}