{"id":9940,"date":"2021-05-14T10:00:57","date_gmt":"2021-05-14T01:00:57","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=9940"},"modified":"2021-05-13T19:26:24","modified_gmt":"2021-05-13T10:26:24","slug":"the-essential-git-commands","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/9940","title":{"rendered":"The essential Git commands"},"content":{"rendered":"\n<p>Why you should learn Git? <\/p>\n\n\n\n<p>Git is the most useful version control system. Git tracks the changes you make to files and collaboration easier and allows multiple people to work on the same files at the same time. <\/p>\n\n\n\n<p>For a new or experienced people using Git is full potential and you need to know Git commands. Here you will learn the essential Git commands that will take you from one level to another.<\/p>\n\n\n\n<p>If you are a new developer, start to learn here Basic Git commands to more Advanced Git commands step by step.<\/p>\n\n\n\n<p>In this section, you will learn the essential foundation Git commands.<\/p>\n\n\n\n<h4>git config<\/h4>\n\n\n\n<p>When you are using Git first-time, you need to customize your Git environment. This command will set up your user name and email address. This is important because every Git commit use this information.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git config --global user.name \u201cYour name\u201d\n$ git config --global user.email \u201cYour email\u201d<\/code><\/pre>\n\n\n\n<h4>git version<\/h4>\n\n\n\n<p>It\u2019s just to check what Git version you are using.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git version<\/code><\/pre>\n\n\n\n<h4>git init<\/h4>\n\n\n\n<p>It creates an empty Git repository for the first command to start a new project in Git. And then you can store your source code inside this repository. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git init<\/code><\/pre>\n\n\n\n<h4>git clone<\/h4>\n\n\n\n<p>The git clone command will use when you need to make a copy of an existing Git repository.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git clone &lt;your project URL><\/code><\/pre>\n\n\n\n<h4>git add<\/h4>\n\n\n\n<p>The git add command will add a new file and modified files,&nbsp; an changes in the working directory to the staging area.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git add &lt;your_file_name> (it will add a single file to your staging area)\n$ git add * ( it will add all the modified and new files to the staging area)<\/code><\/pre>\n\n\n\n<h4>git commit<\/h4>\n\n\n\n<p>This Git commit will add your changes to the local repository.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Here is the usage of the Git commit command.\n$ git commit  \u201cyour useful commit message\u201d<\/code><\/pre>\n\n\n\n<h4>git status<\/h4>\n\n\n\n<p>The git status command displays the state of the working directory and the stating area. It lets you see which changes have been staged, which haven&#8217;t, and which files aren&#8217;t being tracked by <strong>Git<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git status<\/code><\/pre>\n\n\n\n<h4>git branch<\/h4>\n\n\n\n<p>The Git branch command lets you to manage your branches effectively like create, list, rename, switch and delete branches.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\t\nTo list all branches\n$ git branch\n\nTo create a new branch\n$ git branch &lt;branch_name>\n\nTo delete a branch\n$ git branch \u2013d &lt;branch_name><\/code><\/pre>\n\n\n\n<h4>git checkout<\/h4>\n\n\n\n<p>The Git checkout command lets you switch between branches. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git checkout &lt;branch_name><\/code><\/pre>\n\n\n\n<p>You can checkout and create branch at the same time with a single command, like that<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git checkout \u2013b <\/code><\/pre>\n\n\n\n<h4>git remote<\/h4>\n\n\n\n<p>Remote repositories are versions of your project that are hosted on the Internet or network somewhere. Collaborating with others involves managing these remote repositories and pushing and pulling data to and from them when you need to share work.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git remote add &lt;shortname> &lt;url><\/code><\/pre>\n\n\n\n<h4>git push<\/h4>\n\n\n\n<p>With the help of the git\nremote command the&nbsp;<strong>git push<\/strong>&nbsp;command is used to upload local\nrepository content to a remote repository.&nbsp;<strong>Pushing<\/strong>&nbsp;is how you\ntransfer commits from your local repository to a remote repo.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\t\n$ git push -u &lt;short_name> &lt;your_branch_name><\/code><\/pre>\n\n\n\n<h4>git fetch<\/h4>\n\n\n\n<p>The&nbsp;<strong>git fetch<\/strong>&nbsp;command downloads commits, files, and refs from a remote repository into your local repo.&nbsp;<strong>Git fetch<\/strong>&nbsp;is a safer alternative because it pulls in all the commits from your remote but doesn&#8217;t&nbsp;<strong>make<\/strong>&nbsp;any changes to your local files.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage \n$ git fetch<\/code><\/pre>\n\n\n\n<h4>git pull<\/h4>\n\n\n\n<p>The Git pull command downloads the content  and immediately updates your local repository with the latest content. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage \n$ git pull &lt;remote_url><\/code><\/pre>\n\n\n\n<h4>git stash<\/h4>\n\n\n\n<p>This Git command temporarily stores your modified files. You can work in stashed with the following Git command.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage \n$ git stash \nyou need a apply a stash to a branch, simply use apply \n$ git stash apply<\/code><\/pre>\n\n\n\n<h4>git log<\/h4>\n\n\n\n<p>This git log command lets you to review and read a history of everything that happens to a repository.&nbsp; Generally, the <strong>git log<\/strong>&nbsp;is a&nbsp;<strong>record<\/strong>&nbsp;of commits. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage \n$ git log<\/code><\/pre>\n\n\n\n<h4>git rm<\/h4>\n\n\n\n<p>This git rm command lets you to remove files from both the staging index and the working directory. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git rm &lt;your_file_name><\/code><\/pre>\n\n\n\n<h4>git merge<\/h4>\n\n\n\n<p>This git merge command merge two branches you were working on. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git merge &lt;branch_name><\/code><\/pre>\n\n\n\n<h4>git diff<\/h4>\n\n\n\n<p>Diff&nbsp;command is&nbsp;<strong>used<\/strong>&nbsp;in&nbsp;git&nbsp;to track the&nbsp;difference&nbsp;between the changes made on a file. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\nto compare the working directory with the local repo:\n$ git diff HEAD &lt;filename>\nto compare two branches\n$ git diff &lt;source branch> &lt;target branch><\/code><\/pre>\n\n\n\n<h4>git mv<\/h4>\n\n\n\n<p>This git mv command lets you to move files or directories from one place to another . It supports moving single files, multiple files and directories.&nbsp; <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage\n$ git mv &lt;old-file-name> &lt;new-file-name><\/code><\/pre>\n\n\n\n<p>By Ami<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/9940\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/9940\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"The essential Git commands\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/9940\" data-text=\"The essential Git commands\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/9940\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/9940\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Why you should learn Git? Git is the most useful version control system. Git tracks the changes you make to fi [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/9940"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=9940"}],"version-history":[{"count":2,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/9940\/revisions"}],"predecessor-version":[{"id":9944,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/9940\/revisions\/9944"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=9940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=9940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=9940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}