<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Git and Github: For Beginners]]></title><description><![CDATA[Git and Github: For Beginners]]></description><link>https://git-github-commands.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 04:49:53 GMT</lastBuildDate><atom:link href="https://git-github-commands.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Git and Git hub : For Complete Beginners explained with commands]]></title><description><![CDATA[Before jumping into learning about git commands, let us understand what is Git and Git hub in layman’s language ??
What is Git and Git Hub ??

Git → it is a distributed version control system implemented as software, now what is version control syste...]]></description><link>https://git-github-commands.hashnode.dev/git-and-git-hub-for-complete-beginners-explained-with-commands</link><guid isPermaLink="true">https://git-github-commands.hashnode.dev/git-and-git-hub-for-complete-beginners-explained-with-commands</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Git]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[Srujan Pattar]]></dc:creator><pubDate>Mon, 19 Jan 2026 17:41:13 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1768844330194/d99dcf83-7cff-4246-89f8-3f8821c29a51.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Before jumping into learning about git commands, let us understand what is Git and Git hub in layman’s language ??</p>
<p><strong>What is Git and Git Hub ??</strong></p>
<ol>
<li><p>Git → it is a distributed version control system implemented as software, now what is version control system(VCS), it is tracking different version of the code and controlling them.</p>
<p> Other VCS in market are:</p>
<p> 1. Mercurial(Distributed)</p>
<p> 2. Subversion(Centralized)</p>
</li>
<li><p>Git Hub → It is remote server, which is use to push, pull and store the code for collaboration and managing code.</p>
<p> Other platforms in market are:</p>
<p> 1. GitLab(Paid)</p>
<p> 2. Bitbucket(Paid)</p>
<p> Git hub is most widely used remote server among all</p>
</li>
</ol>
<p><strong>Why is Git used ??</strong></p>
<p>Now, consider you are working on a company’s project, so there will be many version of your code, to track all those versions and manage them, we use git(local repo). And the code can be stored in git hub(remote repo) so that it can accessed by other members of your team and work on it. Repo is nothing but a folder with .git folder containing all the history, objects, heads, etc</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768668744208/431bfd53-9d82-4912-abc3-aa12005df253.png" alt class="image--center mx-auto" /></p>
<p><strong>List of Git commands and there usage with workflow:</strong></p>
<p>Git can be used only by git commands, here is list of all commands needed in the sequential order of usage, before that we need to setup our Git, Follow along me:</p>
<p>To setup Git:</p>
<p>Create a new file known as git.py and open integrated terminal, to setup git type:</p>
<pre><code class="lang-plaintext">git config --global user.name "Your name" //to add your username
git config --global user.email "youremail@gmail.com" //to add your email
</code></pre>
<p>Now to check you entered details, type:</p>
<pre><code class="lang-plaintext">git config --global user.name
git config --global user.email //entered email and username will appear
</code></pre>
<p>Now let us write some code in our git.py and learn about git commands:</p>
<pre><code class="lang-python">a=<span class="hljs-number">10</span>
print(a)
</code></pre>
<p>After writing our code, head back to terminal to write our first git command:</p>
<pre><code class="lang-plaintext">git init
</code></pre>
<p>now what does git init does ?? this commands start the initializing repositor in the current directory and creates a .git folder, automatically it will be hidden in the folder. Now lets add the folders that should be tracked by git:</p>
<pre><code class="lang-plaintext">git add git.py //only this file will be tracked
git add . //all files will be tracked(in case of a big code base)
</code></pre>
<p>now lets commit all our tracked files, basically it is like creating check point for code written as of now:</p>
<pre><code class="lang-plaintext">git commit -m "your message" //syntax
git commit -m "first commit"
</code></pre>
<p>In the above code, it is explained with syntax and congrats you made your first commit, now let us modify our code, by adding new code to git.py file</p>
<pre><code class="lang-python">a=<span class="hljs-number">10</span>
print(a) //old code
b=<span class="hljs-number">20</span>
print(b) //adding this code to old code
</code></pre>
<p>Now we can check what all the changes we have made in our code using a git command called as git diff, lets try it out:</p>
<pre><code class="lang-plaintext">git diff
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768838185350/2c3aa33f-b125-4442-9bc1-385baf55225a.png" alt class="image--center mx-auto" /></p>
<p>Code highlighted in red are the code line that are removed and code highlighted in green are the code line that are added newly. Make some new changes in code according to you and commit it once again as:</p>
<pre><code class="lang-plaintext">git add git.py
git commit -m "second"
</code></pre>
<p>Now once your execute this command after making certain changes in your code, lets list out all the commits you have made using git command:</p>
<pre><code class="lang-plaintext">git log
</code></pre>
<p>This command logs all the commits you have made(all the check point) and separate ID will be given to each commit, it will just look like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768838644169/59d1177c-8bce-48af-ac22-7dbd95e52a9f.png" alt class="image--center mx-auto" /></p>
<p>If this looks complex/messy for you, then get details about git logs in single line by a command:</p>
<pre><code class="lang-plaintext">git log --oneline
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768839773937/97b6c397-3d3c-43c0-9dd7-26a16293f11d.png" alt class="image--center mx-auto" /></p>
<p>Here the git id is also shorten and If you look carefully, there is something mentioned as ‘(Head → master)’, if you have studied linked list then you will be knowing about concept called as head, it is nothing but it points to our your latest commit, since our latest commit was committed with message “second”, so head is point to latest commit. It makes traversing between commits easier, so If we add something to the code and later it turns out it was not of our use then, we can go back to our last code, by reverting head. let us understand it better by pictorial representation, consider we have 4 commits in our code then:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768839441409/4474fd36-83a6-4c00-8977-2957b9b05b17.png" alt class="image--center mx-auto" /></p>
<p>Lets understand this better, as we discussed by default head will point to last commit, so it is now pointing to our last commit (fourth commit), we can revert back to any other commit by keeping the last commit or by deleting the previous commit, by using commands:</p>
<pre><code class="lang-plaintext">git revert &lt;commit id&gt; //this will create new commit and keep the last commit without deleting it
git reset --hard &lt;commit id&gt; //this will revert head back to 2nd commit and delete 3rd commit
</code></pre>
<p>Once after executing reset — hard, it will be looking like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768840529667/161cace7-092e-43a0-91c5-e59b62fd6a46.png" alt class="image--center mx-auto" /></p>
<p>Problem of using this command is, it will delete all the previous commits and will jump to commit which you have mentioned in the command, so better to use git reset &lt;commit id&gt;, so that in case you release that the wrong code was right one, once again you can revert back to it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768840777214/d2f368ac-7fe8-493b-826c-1494f45cdc7c.png" alt class="image--center mx-auto" /></p>
<p>even you can untrack the file using git command called as:</p>
<pre><code class="lang-plaintext">git rm &lt;file_name&gt;
</code></pre>
<p>Now it was all about working with git, now let us connect it to Git Hub, by creating a account in Git hub and creating a new repo there, once everything is done, it will something like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768841059680/c3a76145-c95b-415f-8446-afc93500638a.png" alt class="image--center mx-auto" /></p>
<p>Copy the link, which is given as ‘<a target="_blank" href="https://github.com/srujanpattar/git.git">https://github.com/srujanpattar/git.git</a>’ in the above image, you will get a slightly different link as repo name will be different, once that is done, go back to terminal and type the following command:</p>
<pre><code class="lang-plaintext">git branch -M main 
git remote add origin https://github.com/srujanpattar/git.git
</code></pre>
<p>Here are two commands, where first commands creates a branch renamed as main and second commands, link or add your code to the specified repo link, once git push is used, all the code will be pushed to the main branch, and the exact command is:</p>
<pre><code class="lang-plaintext">git push -u origin main
</code></pre>
<p>this command will push your code to the specified repo, and once you type this command and press enter, it will take some time and you will get output as this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768841526594/5c1691ec-2930-434f-a5e1-ae677010a4ab.png" alt class="image--center mx-auto" /></p>
<p>Once done with pushing your code to the repo, now go back to your git hub repo and refresh the site, you will end up to this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768841604278/718b9212-d50f-4a77-bd06-fb132b86f37e.png" alt class="image--center mx-auto" /></p>
<p>Congrats on pushing your code into Git Hub, here you will find some sections as Add a README, it is nothing but you write instructions or explain what is your code/project and how it should be executed, once this pulled to your pc. Let us summarize all the commands and there usage:  </p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Git commands</td><td>Usage</td></tr>
</thead>
<tbody>
<tr>
<td><code>git config - -global user.name &lt;username&gt;</code></td><td>to set username</td></tr>
<tr>
<td><code>git config - -global user.email &lt;email&gt;</code></td><td>to set email</td></tr>
<tr>
<td><code>git init</code></td><td>initialize git in the current directory and a hidden .git folder is created</td></tr>
<tr>
<td><code>git add &lt;file_path&gt; or .</code></td><td>start tracking files and if . is used then all files are staged</td></tr>
<tr>
<td><code>git diff</code></td><td>shows changes done in files (working directory vs staging area)</td></tr>
<tr>
<td><code>git rm &lt;file_path&gt;</code></td><td>remove file from tracking and delete it from working directory</td></tr>
<tr>
<td><code>git commit -m "message"</code></td><td>creates a commit</td></tr>
<tr>
<td><code>git log</code></td><td>list all commits history</td></tr>
<tr>
<td><code>git log --oneline</code></td><td>list all commits in one line</td></tr>
<tr>
<td><code>git reset --hard</code></td><td>head goes back to mentioned commit id and discards later commits and changes</td></tr>
<tr>
<td><code>git revert &lt;commit_id&gt;</code></td><td>creates a new commit and reverses the changes of the specified commit</td></tr>
<tr>
<td><code>git remote add origin &lt;repo_link&gt;</code></td><td>link local repo to remote server</td></tr>
<tr>
<td><code>git push -u origin &lt;branch_name&gt;</code></td><td>pushes code to remote repo for the first time</td></tr>
<tr>
<td><code>git push -f</code></td><td>forced push, used when local history is rewritten and needs to overwrite remote history</td></tr>
</tbody>
</table>
</div>]]></content:encoded></item></channel></rss>