<?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 & GitHub concepts]]></title><description><![CDATA[Git & GitHub concepts]]></description><link>https://mohammed-nadeem.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 16:40:19 GMT</lastBuildDate><atom:link href="https://mohammed-nadeem.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Advance Git & GitHub concepts]]></title><description><![CDATA[◉ What is Git and why is it important?
Git is a tool for version management. So in the IT world developers, DevOps and other teams who are managing and developing the code they are using the Git tool for the code version management for their project ...]]></description><link>https://mohammed-nadeem.hashnode.dev/advance-git-github-concepts</link><guid isPermaLink="true">https://mohammed-nadeem.hashnode.dev/advance-git-github-concepts</guid><category><![CDATA[GitHub]]></category><category><![CDATA[Git]]></category><dc:creator><![CDATA[Mohammed Nadeem]]></dc:creator><pubDate>Sat, 08 Feb 2025 07:45:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739000349283/5a98868b-6721-45af-b700-1242b1e784e6.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-what-is-git-and-why-is-it-important"><strong>◉ What is Git and why is it important?</strong></h1>
<p>Git is a tool for version management. So in the IT world developers, DevOps and other teams who are managing and developing the code they are using the Git tool for the code version management for their project and that is very important as there may be different environments such as Test, UAT, PROD in the real world and all the platform has a different version of code. So basically that is the importance of the source code versioning tool Git.</p>
<h1 id="heading-what-is-the-difference-between-main-branch-and-master-branch">◉ What is the difference Between Main Branch and Master Branch?</h1>
<p>There is no basic difference between main and master branches,</p>
<ol>
<li><p>"Master" Branch: In many version control systems, including Git, the default branch name historically used to be "master." This term dates back to the early days of version control systems when it was commonly used to denote the primary branch or the default development branch. However, in recent years, there has been a movement to transition away from the term "master" due to its association with slavery and to promote more inclusive terminology.</p>
</li>
<li><p>"Main" Branch: In response to the movement mentioned above, many projects and organizations have started adopting the term "main" as an alternative to "master." The "main" branch serves the same purpose as the "master" branch: it represents the default development branch and is typically where the most up-to-date and stable version of the codebase resides. By using "main," these projects aim to promote inclusive language and create a more inclusive and welcoming environment.</p>
</li>
</ol>
<h1 id="heading-can-you-explain-the-difference-between-git-and-github">◉ Can you explain the difference between Git and GitHub?</h1>
<p>Git is the underlying version control system that allows tracking and managing code changes, while GitHub is a platform built on top of Git that provides hosting, collaboration, and project management features. Git can be used independently on local machines, while GitHub provides a centralized platform for hosting and managing Git repositories, facilitating collaboration and community interaction.</p>
<h1 id="heading-how-do-you-create-a-new-repository-on-github">◉ How do you create a new repository on GitHub?</h1>
<ol>
<li><p>In the upper-right corner of any page, use the drop-down menu, and select <strong>New repository</strong>.</p>
<p> <img src="https://docs.github.com/assets/cb-31554/images/help/repository/repo-create.png" alt="Screenshot of a GitHub dropdown menu showing options to create new items. The menu item &quot;New repository&quot; is outlined in dark orange." /></p>
</li>
<li><p>Type a short, memorable name for your repository. For example, "hello-world".</p>
<p> <img src="https://docs.github.com/assets/cb-61138/images/help/repository/create-repository-name.png" alt="Screenshot of the first step in creating a GitHub repository. The &quot;Repository name&quot; field contains the text &quot;hello-world&quot; and is outlined in dark orange." /></p>
</li>
<li><p>Optionally, add a description of your repository. For example, "My first repository on GitHub AE."</p>
</li>
<li><p>Choose repository visibility. For more information, see "<a target="_blank" href="https://docs.github.com/en/github-ae@latest/repositories/creating-and-managing-repositories/about-repositories#about-repository-visibility"><strong>About repositories</strong></a>."</p>
</li>
<li><p>Select <strong>Initialize this repository with a README</strong>.</p>
</li>
<li><p>Click <strong>Create Repository</strong>.</p>
</li>
</ol>
<p>Congratulations! You've successfully created your first repository and initialized it with a <em>README</em> file.</p>
<h1 id="heading-what-is-the-difference-between-local-amp-remote-repositories">◉ What is the difference between local &amp; remote repositories?</h1>
<p>Local and remote repositories are two distinct copies of a project's repository that serve different purposes. Here's an overview of their differences:</p>
<p><strong>Local Repository:</strong></p>
<ul>
<li><p>A local repository resides on your local machine, typically on your computer's hard drive.</p>
</li>
<li><p>It contains the complete history of the project, including all the files, commits, branches, and tags.</p>
</li>
<li><p>Developers work directly with the local repository, making changes, creating branches, and committing code.</p>
</li>
<li><p>Local repositories provide the ability to work offline, experiment with new features, and test changes before sharing them with others.</p>
</li>
</ul>
<p><strong>Remote Repository:</strong></p>
<ul>
<li><p>A remote repository is hosted on a server, typically on a platform like GitHub, GitLab, or Bitbucket.</p>
</li>
<li><p>It serves as a central location where developers can push their local changes and collaborate with others.</p>
</li>
<li><p>Remote repositories facilitate team collaboration, code sharing, and version control across multiple developers or machines.</p>
</li>
<li><p>Remote repositories provide a backup of the project's code, allow for easy sharing and synchronization of changes, and enable access from different locations or devices.</p>
</li>
</ul>
<p>Connecting a Local Repository to a Remote Repository: To connect your local repository to a remote repository, follow these general steps:</p>
<ol>
<li><p>Create a Remote Repository: First, create a remote repository on the platform of your choice (e.g., GitHub). This is typically done through the platform's interface or by using their API.</p>
</li>
<li><p>Initialize Git in your Local Repository: If you haven't already, navigate to your local repository directory using the command line or a Git GUI tool. Run the command <code>git init</code> to initialize Git within that directory.</p>
</li>
<li><p>Link the Local and Remote Repositories: In your local repository, add the URL of the remote repository as a remote. For example, if your remote repository is on GitHub, you can use the command <code>git remote add origin &lt;remote repository URL&gt;</code> to add it as the "origin" remote.</p>
</li>
<li><p>Push Local Changes to the Remote Repository: After linking the repositories, you can push your local commits to the remote repository using the command <code>git push origin &lt;branch name&gt;</code>. This will upload your local commits to the corresponding branch in the remote repository.</p>
</li>
<li><p>Pull Remote Changes to Local Repository: If there are changes in the remote repository that you want to incorporate into your local repository, you can use the command <code>git pull origin &lt;branch name&gt;</code> to pull and merge those changes into your local branch.</p>
</li>
</ol>
<p>These steps provide a general outline of connecting a local repository to a remote repository. The specific commands and procedures may vary depending on the hosting platform and your specific project setup. It's recommended to refer to the documentation or guides provided by the platform you are using (e.g., GitHub, GitLab) for more detailed instructions on setting up and configuring your remote repository.</p>
<h1 id="heading-operations-using-git-and-github">◉ Operations using Git and GitHub</h1>
<h2 id="heading-set-your-user-name-and-email-address-which-will-be-associated-with-your-commits">◎ Set your user name and email address, which will be associated with your commits.</h2>
<pre><code class="lang-plaintext">$ git config --global user.name "Nildip" 
$ git config --global user.email "test@gmail.com"
</code></pre>
<p>Why do we need to set the user name and user email? Because when we commit the code that time it needs the user who did commit. so everybody's commit will be registered in their name and we can get to know who did this commit and other details.</p>
<ul>
<li><p>Create a repository named "git-test-repo" on GitHub</p>
</li>
<li><p>Connect your local repository to the repository on GitHub.</p>
</li>
<li><p>Create a new file in git-test-repo/<a target="_blank" href="http://readme.md/"><strong>README.md</strong></a> &amp; add some content to it</p>
</li>
<li><p>Push your local commits to the repository on GitHub</p>
</li>
</ul>
<pre><code class="lang-plaintext">$ echo "# git-test-repo" &gt;&gt; README.md
$ git init
$ git add README.md
$ git commit -m "first commit"
$ git branch -M main
$ git remote add origin https://github.com/patelnildip/git-test-repo.git
$ git push -u origin main
</code></pre>
<h2 id="heading-git-commands"><strong>◎ Git Commands</strong></h2>
<h3 id="heading-creating-snapshot">○ Creating Snapshot</h3>
<p><strong>Initializing a repository</strong></p>
<p><code>$ git init</code></p>
<p><strong>Staging files</strong></p>
<p><code>git add file1.js</code> # Stages a single file</p>
<p><code>git add file1.js file2.js</code> # Stages multiple files</p>
<p><code>git add *.js</code># Stages with a pattern</p>
<p><code>git add .</code># Stages the current directory and all its content</p>
<p><strong>Viewing the status</strong></p>
<p><code>git status</code> #full status</p>
<p><code>git status -s</code> #Short status</p>
<p><strong>Committing the staged files</strong></p>
<p><code>git commit -m “Message”</code> # Commits with a one-line message</p>
<p><code>git commit</code> # Opens the default editor to type a long message</p>
<p><strong>Skipping the staging area</strong></p>
<p><code>git commit -am “Message”</code></p>
<p><strong>Removing files</strong></p>
<p><code>git rm file1.js</code> # Removes from working directory and staging area</p>
<p><code>git rm --cached file1.js</code> # Removes from staging area only</p>
<p><strong>Renaming or moving files</strong></p>
<p><code>git mv file1.js file1.txt</code></p>
<p><strong>Viewing the staged/unstaged changes</strong></p>
<p><code>git diff</code># Shows unstaged changes</p>
<p><code>git diff --staged</code># Shows staged changes</p>
<p><code>git diff --cached</code># Same as the above</p>
<p><strong>Viewing the history</strong></p>
<p><code>git log</code> # Full history</p>
<p><code>git log --oneline</code> # Summary</p>
<p><code>git log --reverse</code> # Lists the commits from the oldest to the newest</p>
<p>Viewing a commit</p>
<p><code>git show 921a2ff</code> # Shows the given commit</p>
<p><code>git show HEAD</code># Shows the last commit</p>
<p><code>git show HEAD~2</code># Two steps before the last commit</p>
<p><code>git show HEAD:file.js</code># Shows the version of file.js stored in the last commit</p>
<p><strong>Unstaging files (undoing git add)</strong></p>
<p><code>git restore --staged file.js</code> # Copies the last version of file.js from repo to the index</p>
<p><strong>Discarding local changes</strong></p>
<p><code>git restore file.js</code># Copies file.js from index to working directory</p>
<p><code>git restore file1.js file2.js</code># Restores multiple files in working directory</p>
<p><code>git restore .</code> # Discards all local changes (except untracked files)</p>
<p><code>git clean -fd</code># Removes all untracked files</p>
<p><strong>Restoring an earlier version of a file</strong></p>
<p><code>git restore --source=HEAD~2 file.js</code></p>
<h3 id="heading-browsing-history">○ Browsing History</h3>
<p><strong>Viewing the history</strong></p>
<p><code>git log --stat</code> # Shows the list of modified files</p>
<p><code>git log --patch</code> # Shows the actual changes (patches)</p>
<p><strong>Filtering the history</strong></p>
<p><code>git log -3</code># Shows the last 3 entries</p>
<p><code>git log --author=“Mosh”</code></p>
<p><code>git log --before=“2020-08-17”</code></p>
<p><code>git log --after=“one week ago”</code></p>
<p><code>git log --grep=“GUI”</code> # Commits with “GUI” in their message</p>
<p><code>git log -S“GUI”</code> # Commits with “GUI” in their patches</p>
<p><code>git log hash1..hash2</code> # Range of commits</p>
<p><code>git log file.txt</code> # Commits that touched file.txt</p>
<p><strong>Formatting the log output</strong></p>
<p><code>git log --pretty=format:”%an committed %H”</code></p>
<p><strong>Creating an alias</strong></p>
<p><code>git config --global alias.lg “log --oneline"</code></p>
<p><strong>Viewing a commit</strong></p>
<p><code>git show HEAD~2</code></p>
<p><code>git show HEAD~2:file1.txt</code> # Shows the version of the file stored in this commit</p>
<p><strong>Comparing commits</strong></p>
<p><code>git diff HEAD~2 HEAD</code> # Shows the changes between two commits</p>
<p><code>git diff HEAD~2 HEAD file.txt</code> # Changes to file.txt only</p>
<p><strong>Checking out a commit</strong></p>
<p><code>git checkout dad47ed</code> # Checks out the given commit</p>
<p><code>git checkout master</code> # Checks out the master branch</p>
<p><strong>Finding a bad commit</strong></p>
<p><code>git bisect start</code></p>
<p><code>git bisect bad</code># Marks the current commit as a bad commit</p>
<p><code>git bisect good ca49180</code># Marks the given commit as a good commit</p>
<p><code>git bisect reset</code># Terminates the bisect session</p>
<p><strong>Finding contributors</strong></p>
<p><code>git shortlog</code></p>
<p><strong>Viewing the history of a file</strong></p>
<p><code>git log file.txt</code># Shows the commits that touched file.txt</p>
<p><code>git log --stat file.txt</code> # Shows statistics (the number of changes) for file.txt</p>
<p><code>git log --patch file.txt</code># Shows the patches (changes) applied to file.txt</p>
<p><strong>Finding the author of lines</strong></p>
<p><code>git blame file.txt</code> # Shows the author of each line in file.txt</p>
<p><strong>Tagging</strong></p>
<p><code>git tag v1.0</code># Tags the last commit as v1.0</p>
<p><code>git tag v1.0 5e7a828</code># Tags an earlier commit</p>
<p><code>git tag</code># Lists all the tags</p>
<p><code>git tag -d v1.0</code># Deletes the given tag</p>
<h3 id="heading-branching-amp-merging">○ Branching &amp; Merging</h3>
<p><strong>Managing branches</strong></p>
<p><code>git branch bugfix</code> # Creates a new branch called bugfix</p>
<p><code>git checkout bugfix</code> # Switches to the bugfix branch</p>
<p><code>git switch bugfix</code># Same as the above</p>
<p><code>git switch -C bugfix</code># Creates and switches</p>
<p><code>git branch -d bugfix</code># Deletes the bugfix branch</p>
<p><strong>Comparing branches</strong></p>
<p><code>git log master..bugfix</code> # Lists the commits in the bugfix branch not in master</p>
<p><code>git diff master..bugfix</code> # Shows the summary of changes</p>
<p><strong>Stashing</strong></p>
<p><code>git stash push -m “New tax rules”</code># Creates a new stash</p>
<p><code>git stash list</code># Lists all the stashes</p>
<p><code>git stash show stash@{1}</code> # Shows the given stash</p>
<p><code>git stash show 1</code># shortcut for stash@{1}</p>
<p><code>git stash apply 1</code> # Applies the given stash to the working dir</p>
<p><code>git stash drop 1</code> # Deletes the given stash</p>
<p><code>git stash clear</code># Deletes all the stashes</p>
<p><strong>Merging</strong></p>
<p><code>git merge bugfix</code># Merges the bugfix branch into the current branch</p>
<p><code>git merge --no-ff bugfix</code># Creates a merge commit even if FF is possible</p>
<p><code>git merge --squash bugfix</code> # Performs a squash merge</p>
<p><code>git merge --abort</code> # Aborts the merge</p>
<p><strong>Viewing the merged branches</strong></p>
<p><code>git branch --merged</code># Shows the merged branches</p>
<p><code>git branch --no-merged</code># Shows the unmerged branches</p>
<p><strong>Rebasing</strong></p>
<p><code>git rebase master</code> # Changes the base of the current branch</p>
<p><strong>Cherry picking</strong></p>
<p><code>git cherry-pick dad47ed</code> # Applies the given commit on the current branch</p>
<h3 id="heading-collaboration">○ Collaboration</h3>
<p><strong>Cloning a repository</strong></p>
<p><code>git clone &lt;url&gt;</code></p>
<p><strong>Syncing with remotes</strong></p>
<p><code>git fetch origin master</code> # Fetches master from origin</p>
<p><code>git fetch origin</code># Fetches all objects from origin</p>
<p><code>git fetch</code># Shortcut for “git fetch origin”</p>
<p><code>git pull</code># Fetch + merge</p>
<p><code>git push origin master</code> # Pushes master to origin</p>
<p><code>git push</code># Shortcut for “git push origin master”</p>
<p><strong>Sharing tags</strong></p>
<p><code>git push origin v1.0</code># Pushes tag v1.0 to origin</p>
<p><code>git push origin —delete v1.0</code></p>
<p><strong>Sharing branches</strong></p>
<p><code>git branch -r</code># Shows remote tracking branches</p>
<p><code>git branch -vv</code># Shows local &amp; remote tracking branches</p>
<p><code>git push -u origin bugfix</code># Pushes bugfix to origin</p>
<p><code>git push -d origin bugfix</code># Removes bugfix from origin</p>
<p><strong>Managing remotes</strong></p>
<p><code>git remote</code># Shows remote repos</p>
<p><code>git remote add upstream &lt;url&gt;</code># Adds a new remote called upstream</p>
<p><code>git remote rm upstream</code># Remotes upstream</p>
<h3 id="heading-rewriting-history">○ Rewriting History</h3>
<p><strong>Undoing commits</strong></p>
<p><code>git reset --soft HEAD^</code> # Removes the last commit, keeps changed staged</p>
<p><code>git reset --mixed HEAD^</code> # Unstages the changes as well</p>
<p><code>git reset --hard HEAD^</code># Discards local changes</p>
<p><strong>Reverting commits</strong></p>
<p><code>git revert 72856ea</code> # Reverts the given commit</p>
<p><code>git revert HEAD~3..</code># Reverts the last three commits</p>
<p><code>git revert --no-commit HEAD~3..</code></p>
<p><strong>Recovering lost commits</strong></p>
<p><code>git reflog</code># Shows the history of HEAD</p>
<p><code>git reflog show bugfix</code># Shows the history of bugfix pointer.</p>
<p><strong>Amending the last commit</strong></p>
<p><code>git commit --amend</code></p>
<p><strong>Interactive rebasing</strong></p>
<p><code>git rebase -i HEAD~5</code></p>
<p>Thanks for reading the blog!</p>
]]></content:encoded></item></channel></rss>