<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>git Archives - Program Easily</title>
	<atom:link href="https://programeasily.com/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>https://programeasily.com/tag/git/</link>
	<description>Program Easily helps people to learn about software programs in a easy manner.</description>
	<lastBuildDate>Fri, 16 Jul 2021 17:24:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>

<image>
	<url>https://i0.wp.com/programeasily.com/wp-content/uploads/2020/12/cropped-logo.png?fit=32%2C32&#038;ssl=1</url>
	<title>git Archives - Program Easily</title>
	<link>https://programeasily.com/tag/git/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">187075990</site>	<item>
		<title>Basic Git Commands &#8211; Part 1</title>
		<link>https://programeasily.com/2021/07/16/basic-git-commands-part-1/</link>
					<comments>https://programeasily.com/2021/07/16/basic-git-commands-part-1/#respond</comments>
		
		<dc:creator><![CDATA[Rachel]]></dc:creator>
		<pubDate>Fri, 16 Jul 2021 17:24:13 +0000</pubDate>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[git]]></category>
		<guid isPermaLink="false">https://programeasily.com/?p=258</guid>

					<description><![CDATA[<p>Tracking the source code during the development is a tiresome job. Git is a software which helps us in this area. It is a free open source Version Control System. It helps developers to coordinate the source management and saves a lot of time for maintaining it. Git not only helps to keep track of changes made to file, in addition we can revert to previous versions when needed and much more. In this section of Basic Git Commands &#8211;...</p>
<p class="read-more"><a class="btn btn-default" href="https://programeasily.com/2021/07/16/basic-git-commands-part-1/"> Read More<span class="screen-reader-text">  Read More</span></a></p>
<p>The post <a rel="nofollow" href="https://programeasily.com/2021/07/16/basic-git-commands-part-1/">Basic Git Commands &#8211; Part 1</a> appeared first on <a rel="nofollow" href="https://programeasily.com">Program Easily</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span style="font-weight: 400;">Tracking the source code during the development is a tiresome job. </span><b><i>Git </i></b><span style="font-weight: 400;">is a software which helps us in this area. It is a free open source <strong>Version Control System</strong>. It helps developers to coordinate the source management and saves a lot of time for maintaining it. Git not only helps to keep track of changes made to file, in addition we can revert to previous versions when needed and much more. In this section of Basic Git Commands &#8211; Part 1, we will see some of the basic git commands that come in use very frequently.</span></p>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-492" src="https://i0.wp.com/programeasily.com/wp-content/uploads/2021/07/Basic-Git-Commands-–-Part-1.jpg?resize=640%2C400&#038;ssl=1" alt="Basic Git Commands – Part 1" width="640" height="400" srcset="https://i0.wp.com/programeasily.com/wp-content/uploads/2021/07/Basic-Git-Commands-–-Part-1.jpg?w=1920&amp;ssl=1 1920w, https://i0.wp.com/programeasily.com/wp-content/uploads/2021/07/Basic-Git-Commands-–-Part-1.jpg?resize=300%2C188&amp;ssl=1 300w, https://i0.wp.com/programeasily.com/wp-content/uploads/2021/07/Basic-Git-Commands-–-Part-1.jpg?resize=1024%2C640&amp;ssl=1 1024w, https://i0.wp.com/programeasily.com/wp-content/uploads/2021/07/Basic-Git-Commands-–-Part-1.jpg?resize=768%2C480&amp;ssl=1 768w, https://i0.wp.com/programeasily.com/wp-content/uploads/2021/07/Basic-Git-Commands-–-Part-1.jpg?resize=1536%2C960&amp;ssl=1 1536w, https://i0.wp.com/programeasily.com/wp-content/uploads/2021/07/Basic-Git-Commands-–-Part-1.jpg?resize=432%2C270&amp;ssl=1 432w, https://i0.wp.com/programeasily.com/wp-content/uploads/2021/07/Basic-Git-Commands-–-Part-1.jpg?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></p>
<h2 style="text-align: center;">Basic Git Commands &#8211; Part 1</h2>
<h2>git init</h2>
<p><em>We can use the  <code>git init</code></em> command to create a new empty git repository or to convert an existing project into a g<em>it</em> project in your local. It will create a <em>.git</em> directory in the current working directory which contains all the metadata like refs/heads, objects, refs/tags etc.</p>
<pre><code class="language-git">$ git init
Initialized empty Git repository in D:/git-basic/first/.git/
</code></pre>
<p>However &#8216; D:/git-basic/first &#8216; is the local path where we have initialized the project.</p>
<h2>git clone</h2>
<p>We can use the <em><code>git clone</code></em> command to clone a remote repository to a new local repository. This will make the repo available in our local system. Technically this will act as a remote repository URL for our project.</p>
<blockquote><p><em>git clone &lt;URL&gt;</em></p></blockquote>
<pre><code class="language-git">$ git clone https://github.com/programeasily/git-basic.git
Cloning into 'git-basic'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (6/6), done.
</code></pre>
<h2>git status</h2>
<p>It describes the status of the current working directory. <em><code>git status</code></em> shows state of current working directory and staging area. It shows files that are not tracked by g<em>it</em>, changes that are staged , which are not staged and deleted files.</p>
<pre><code class="language-git">$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add &lt;file&gt;..." to include in what will be committed)
        programEasily.java

nothing added to commit but untracked files present (use "git add" to track)
</code></pre>
<h2>git stash</h2>
<p><span style="font-weight: 400;"><em><code>git stash</code></em> removes the uncommitted changes in a working directory and makes the directory clean. When one has to switch branches we can use git stash. It cleans the working directory and makes a head point to the last commit.</span></p>
<pre><code class="language-git">$ git stash
Saved working directory and index state WIP on master: 9a2ef8f hii
</code></pre>
<h2>git branch</h2>
<p><em><code>git branch</code></em> command create a new branch from the master branch, delete an existing branch and list the branches. Let us see one by one.</p>
<h3>create new branch</h3>
<p><span style="font-weight: 400;">Firstly, one can use the <em><code>git branch &lt;newBranchName&gt;</code></em></span><em><span style="font-weight: 400;"> </span></em><span style="font-weight: 400;"> command to create a new branch. Branching is the integral part of the </span><span style="font-weight: 400;">Git</span><span style="font-weight: 400;"> version control mechanism. New branch can be created with any branch as reference. The default branch in </span><span style="font-weight: 400;">Git</span><span style="font-weight: 400;"> is </span><span style="font-weight: 400;">master.</span></p>
<blockquote><p>git branch git-basic-ver1</p></blockquote>
<h3>delete branch</h3>
<p>Secondly, we can use <span style="font-weight: 400;"><em><code>git branch -d &lt;branchName&gt;</code></em></span> <em> </em>to remove the branch locally. This will remove the branch only if the changes are committed and pushed to remote repo.</p>
<pre><code class="language-git">$ git branch -d git-basic-ver1
Deleted branch git-basic-ver1 (was 9a2ef8f).
</code></pre>
<p>If your branch contains commits that have not been merged or pushed to remote repo one need to use <span style="font-weight: 400;"><em><code>git branch -D &lt;branchName&gt;</code></em></span>. This will force the branch deletion.</p>
<h3>list branch</h3>
<p><span style="font-weight: 400;">View the local branches in your repository using the <em><code>git branch</code></em></span><i><span style="font-weight: 400;">.</span></i></p>
<pre><code class="language-git">$ git branch
git-basic-ver1
* master</code></pre>
<p>To show the branches in a remote Git repository, one need to use <span style="font-weight: 400;"><em><code>git branch -r</code></em></span><em><em>.</em></em></p>
<pre><code class="language-git">$ git branch -r
  origin/master</code></pre>
<p>To list the local and remote branches to a repository</p>
<pre><code class="language-git">$ git branch -a
  git-basic-ver1
* master
  remotes/origin/master</code></pre>
<h2>git checkout</h2>
<p>We can use the checkout command to switch from the current active branch to another. While we switch the branch, it may ask to stage and the staged files, commits might be lost.</p>
<blockquote><p><em>git checkout  &lt;branchname&gt;</em></p></blockquote>
<pre><code class="language-git">$ git checkout git-basic-ver1
Switched to branch 'git-basic-ver1'
</code></pre>
<p>One can also create and switch to a new branch using the <em>git checkout</em> command.</p>
<pre><code class="language-git">$ git checkout -b git-basic-ver2
Switched to a new branch 'git-basic-ver2'
</code></pre>
<p>Here It will add untracked files to the new branch unless there is no conflict.</p>
<h2>git fetch</h2>
<p><span style="font-weight: 400;"><em><code>git fetch</code> </em></span>operation will download new data (commits, refs, branches etc) from remote repository to local repository. A fetch command will never make any change to the local repository. It just provides a view of changes made in remote repo.</p>
<pre><code class="language-git">$ git fetch origin
</code></pre>
<h2>git pull</h2>
<p><span style="font-weight: 400;"><em><code>git pull</code> </em></span>does the function of fetch command and additionally <span style="font-weight: 400;">integrates </span> the downloaded new data from remote repo with the local repository. <span style="font-weight: 400;"><em><code>git pull</code></em></span> should be performed in a clean repo with no uncommitted changes. Since it <span style="font-weight: 400;">integrates </span> remote repo changes with local directory merge conflicts may occur which should be taken care.</p>
<p>In the other words, we can say <span style="font-weight: 400;"><em><code>git pull</code></em></span> can refer to the combination of <span style="font-weight: 400;"><em><code>git fetch</code></em></span> followed by a <span style="font-weight: 400;"><em><code>git merge</code></em></span>.</p>
<pre><code class="language-git">$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull &lt;remote&gt; &lt;branch&gt;

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=&lt;remote&gt;/&lt;branch&gt; git-basic-ver2
</code></pre>
<h2>git version</h2>
<p>In order to check the current version of git, you can use <span style="font-weight: 400;"><em><code>git --version</code> </em></span>command.</p>
<pre><code class="language-git">$ git --version
git version 2.30.0.windows.2
</code></pre>
<h2>git add</h2>
<p>In order to add the changes from the local workspace to the staging area, we can use the <span style="font-weight: 400;"><em><code>git add</code></em></span> command. It prepares the changes for the next commit. It does not make changes to the remote repository. <span style="font-weight: 400;">These changes can include new, existing or deleted files and directories.</span><span style="font-weight: 400;"> </span></p>
<blockquote><p><em>git add &lt;filePath&gt;</em></p></blockquote>
<p><span style="font-weight: 400;">With the <em><code>git add</code></em> command you have to specify the file or directory path one needs to add to the staging area. You can add single as well as multiple paths.</span></p>
<pre><code class="language-git">$ git add basic/programEasily.java
</code></pre>
<h2>git commit</h2>
<p><span style="font-weight: 400;">This command commits the changes added in the staging area. One uses immediately after the <em><code>git add</code></em></span><span style="font-weight: 400;"> command. It can be done with a commit message which helps to understand what this commit is all about easily in future.</span></p>
<blockquote><p><em>git commit -m &#8220;message&#8221;</em></p></blockquote>
<p>Note that, It will records every commit in the master branch.</p>
<pre><code class="language-git">$ git commit -m 'ver1 code'
[git-basic-ver1 e95c217] ver1 code
1 file changed, 1 insertion(+)</code></pre>
<p><span style="font-weight: 400;">This g<em>it</em> command does not commit the changes to the remote repository, but adds to the local one.</span></p>
<h2>git push</h2>
<p><span style="font-weight: 400;"><em><code>git push</code></em></span> command moves the local commit changes to the remote repository. This will make the commits recorded in the master branch and changes can be used by remote the repository users.</p>
<blockquote><p><em>git push &lt;branchName&gt;</em></p></blockquote>
<p>You should be cautious while pushing the changes to the remote repository because it will overwrite the previous contents.</p>
<pre><code class="language-git">$ git push Enumerating objects: 7, done. 
Counting objects: 100% (7/7), done. 
Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. 
Writing objects: 100% (4/4), 336 bytes | 168.00 KiB/s, done. Total 4 (delta 0), 
reused 0 (delta 0), pack-reused 0 
To https://github.com/programeasily/git-basic.git 9261bc4..e95c217 git-basic-ver1 -&gt; git-basic-ver1</code></pre>
<h2>git amend</h2>
<p>We can use the <span style="font-weight: 400;"><em><code>git amend</code></em></span> command to edit the recent commit. It adds new changes with the commit in the staged area and in addition it will create a new commit replacing the old one.</p>
<blockquote><p><em>git commit &#8211;amend &#8216;message&#8217;</em></p></blockquote>
<pre><code class="language-git">$ git commit --amend -m 'changes'
[git-basic-ver1 6439b3e] changes
 Date: Mon Jun 14 11:37:08 2021 +0530
 1 file changed, 1 insertion(+), 1 deletion(-)
</code></pre>
<h2>git diff</h2>
<p><span style="font-weight: 400;">It compares and shows differences between commits, branches or changes made in the working directory since the last commit etc.</span></p>
<blockquote><p><em>git diff &#8211;  </em>shows changes done in the working directory since the last commit.</p></blockquote>
<pre><code class="language-git">$ git diff
diff --git a/basic/programEasily.java b/basic/programEasily.java
index 33545ed..b175a51 100644
--- a/basic/programEasily.java
+++ b/basic/programEasily.java
@@ -1 +1 @@
-sample1
+This is a sample file.
\ No newline at end of file</code></pre>
<h2>git reset &#8211;hard</h2>
<p><span style="font-weight: 400;">Removes the changes in the operated repository. In other words, it will remove the changes in the working directory of the staging index and roll back to the previous commit. Since, it is the most unsafe reset, once performed cannot be undone.</span></p>
<pre><code class="language-git">$ git reset --hard
HEAD is now at 6439b3e changes
</code></pre>
<h2>set username and email</h2>
<h3><em>git config &#8211;global user.name</em></h3>
<p>it shows the username for your git repository installed in your system. Any change or commit you perform will be recorded in this name.</p>
<blockquote><p>$ git config &#8211;global user.name rachel</p></blockquote>
<h3><em>git config &#8211;global user.email</em></h3>
<p>It helps to view the git user email recorded in your system.</p>
<blockquote><p>$ git config &#8211;global user.email rachel@gmail.com</p></blockquote>
<p>In addition, if one has to change the email use ,</p>
<blockquote><p>$ git config &#8211;global user.email &lt;email&gt;</p></blockquote>
<p>One can change the username and email for a particular project by removing &#8211;global from above commands.</p>
<h2>Summary of Basic Git Commands – Part 1</h2>
<ul>
<li>In conclusion of Basic Git Commands &#8211; Part 1, we have seen some of the most commonly used <em>git</em> commands.  We will be using these commands commonly in the daily life of a developer.</li>
<li>In the coming sections we will see about some other useful git commands.</li>
</ul>
<h2>You may Also Like</h2>
<ul>
<li><a href="https://programeasily.com/vue/">https://programeasily.com/vue/</a></li>
<li><a href="https://programeasily.com/2021/06/20/react-best-free-admin-dashboard-template-in-2021/">https://programeasily.com/2021/06/20/react-best-free-admin-dashboard-template-in-2021/</a></li>
</ul>
<p>The post <a rel="nofollow" href="https://programeasily.com/2021/07/16/basic-git-commands-part-1/">Basic Git Commands &#8211; Part 1</a> appeared first on <a rel="nofollow" href="https://programeasily.com">Program Easily</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://programeasily.com/2021/07/16/basic-git-commands-part-1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">258</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Page Caching using disk: enhanced 
Minified using disk
Database Caching 19/43 queries in 0.028 seconds using disk (Request-wide modification query)

Served from: programeasily.com @ 2025-06-20 07:36:50 by W3 Total Cache
-->