<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ajaytumula</title>
    <description>The latest articles on Forem by Ajaytumula (@ajaytumula2).</description>
    <link>https://forem.com/ajaytumula2</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1063978%2F249cab20-6454-46e8-8a15-01abcf70e393.jpeg</url>
      <title>Forem: Ajaytumula</title>
      <link>https://forem.com/ajaytumula2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ajaytumula2"/>
    <language>en</language>
    <item>
      <title>Know about Git and GitHub in simple way✨</title>
      <dc:creator>Ajaytumula</dc:creator>
      <pubDate>Sat, 10 Jun 2023 11:35:02 +0000</pubDate>
      <link>https://forem.com/ajaytumula2/know-about-git-and-github-in-simple-way-4haa</link>
      <guid>https://forem.com/ajaytumula2/know-about-git-and-github-in-simple-way-4haa</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Git ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is a free and open-source version control system.&lt;br&gt;
If you have a code implemented and kept at some place and if you want to refer and check that code later, you can do that with the help of Git, and if you want to want to contribute to open source then you can use Git.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is version control system ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The management of changes to documents, computer programs, large websites, and other collections of information. Git is the version control system, that helps the software development teams to manage and control the changes made to software by each developer. Thus, keeping track of the version changes and better error detections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is GitHub ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GitHub is a website or UI platform that helps us to host the repositories that is the source code folders. To use this platform, we need to know how to create a repository, clone a repository, fork a repository and the commands to interact with the developer local machine and the GitHub platform.&lt;/p&gt;

&lt;p&gt;Initially you need to download Git, the link to download Git is 👇&lt;br&gt;
&lt;em&gt;&lt;a href="https://git-scm.com/downloads"&gt;https://git-scm.com/downloads&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this blog I will simplify 🤝 the approach to work with the Git repositories into three different scenarios🫵.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario-1&lt;/strong&gt;:&lt;br&gt;
To create a repository, go to "your repositories" icon in your GitHub profile section, once you click on the new button then a screen to create new repository opens, where you can create a new repository by mentioning a repository name.&lt;br&gt;
Once you have created the repository on the GitHub platform, then you need to clone that repository into your local machine, to clone a repository, you need to:&lt;/p&gt;

&lt;p&gt;· Use the command git clone and copy paste the URL of the repository.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/AjayTumula/StrugglersInDev-Git.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Then you can open the repository in any of your local IDE based on the programming language such as IntelliJ, Eclipse, PyCharm, Visual studio code etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario-2&lt;/strong&gt;:&lt;br&gt;
If you want to work on other's repository or want to contribute to other's repository then you must fork the repository, that will create a copy of the repository with your name in your repository lists. You must select the fork icon on the GitHub UI. Then you need to clone the repository(URL) to get the repository or project in your local machine.&lt;/p&gt;

&lt;p&gt;· The command to do that is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone &amp;lt;&amp;lt;repository_url&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· From where you forked the project is known as upstream URL by convention so to add the upstream URL we use the command below 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add upstream &amp;lt;&amp;lt;repository_url&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· The command to check the URLs, you use the below command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Scenario-3&lt;/strong&gt;:&lt;br&gt;
Now, lets consider if you have project or repository in your local machine and you want to add it to your GitHub. Then you need to follow the commands 👇&lt;/p&gt;

&lt;p&gt;· At first you need to initialize git by using the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Then an empty git repository is initialized in your local machine. &lt;br&gt;
For example,&lt;br&gt;
Initialized empty Git repository in C:/Users/ajayt/java/NewProject/.git/&lt;/p&gt;

&lt;p&gt;· Then after initializing an empty git repository, we need to add all the file created and the changes made to the files using the command, git add . this command is used to add all the files. If you want to add a specific file then use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add &amp;lt;&amp;lt;nameOfTheSpecificFile&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✨ This git add command adds all the files to the staging area.&lt;/p&gt;

&lt;p&gt;· After adding all the files to the staging area then you need to commit your changes, to commit the changes use the below command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "first commit"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The message in the double quotes is used to indicate the commit and it is always represented in double quotes.&lt;/p&gt;

&lt;p&gt;· Then you need to add the remote repository to your local repository for that you use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin https://github.com/AjayTumula/StrugglersInDev-Git.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Once the remote repository is added, you need create a branch before you push the changes made, the command used to create a branch is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch -M main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· After creating a branch to push the changes to the repository we use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· You can see the files changed, and insertions made to the file after pushing all the latest changes.&lt;/p&gt;

&lt;p&gt;The below figure shows the file changes👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Lls4u9M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sb222wvo7qpiqc0ebtfn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Lls4u9M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sb222wvo7qpiqc0ebtfn.png" alt="Image description" width="715" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also see all the repository setup commands once you create a repository on the GitHub platform, the below 👇 screenshot shows the following commands to create a repository on the command line.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jcmC-G-3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5vpwjmy2h8x9idhmmuxb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jcmC-G-3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5vpwjmy2h8x9idhmmuxb.png" alt="Image description" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I mentioned staging area there is another point to consider like if you want to make changes to the file and want to keep all the changes safe at a place so that you can add and commit the changes later then you need backstage your changes that is keeping your changes in an unstaged area (If you want to keep your changes safe at some other place other than committing it or deleting it then you need to stash your changes).&lt;/p&gt;

&lt;p&gt;Here comes the git stash command, which is used to save the local modifications away and reverts the working directory to match the HEAD commit. &lt;/p&gt;

&lt;p&gt;⭐ Head is the pointer which points towards the branch.&lt;/p&gt;

&lt;p&gt;· The command used to backstage the file is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash or git stash push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· To remove a single stashed state from the stash list and apply it on top of the current working tree state, use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· The command to clear all the stashed files is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· To restore a file which is deleted unfortunately, use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git restore –staged &amp;lt;&amp;lt;nameOfTheFile&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Commits in the Git&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Each commit in the git are built on top of each other and Each commit in the git has a HashId.&lt;/p&gt;

&lt;p&gt;Git and GitHub allows you to maintain the history of the project, which helps us to know which person made what change in the project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are branches in Git ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The branch is something which is created to make changes, initially a user must create a branch instead of pushing the code changes directly to the main or master account.&lt;/p&gt;

&lt;p&gt;· The command used to create a branch is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch &amp;lt;&amp;lt;branchname&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· The command used to navigate to a branch is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout &amp;lt;&amp;lt;branchname&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⭐&lt;strong&gt;Note&lt;/strong&gt;: One branch can open one pull request. In simple terms one branch is one pull request. We can only open new pull request with new branches. And here if a branch has already had a open pull requests all the next commits will be committed to that branch.&lt;/p&gt;

&lt;p&gt;· If you want to delete an extra commit in your branch then you need to use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset &amp;lt;&amp;lt;hashidofcommitonebelowwhichneedtoberemoved&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Then that commit or change will be unstaged or removed, after that use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· And now to backstage the changes use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· After that if you use this command you will only see the commit which you wanted the extra one will be removed from there. The command is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you want to push this change you need to force push this change as the online repository contains the commit which the local repository doesn't. The command to force the change is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin main -f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, now if you want to keep your forked repository updated with the main repository then you need fetch the upstream URL. You can do this in two ways one is with option on UI by clicking on the refresh button below the code button in the GitHub platform and the other is using the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git pull upstream main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What are merge conflicts and how we resolve them ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In simple terms when two developers or peoples make the changes in the same line, then git gets confused about the changes made.&lt;br&gt;
You need to resolve the conflict manually.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Squashing your commit&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;If you have a lot of commit and want to merge that commits into one commit, then the command for that is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase -i &amp;lt;&amp;lt;below_commit_url&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Some useful Git commands and information&lt;/strong&gt;😍:&lt;/p&gt;

&lt;p&gt;· To initialize git in the local machine we use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· To know about the code changes in the local machine we use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Any changes made to current files in the local machine are added to the staging area with the use of the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Example of the add command is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add &amp;lt;&amp;lt;nameofthefile&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· To commit the changes which are added to the staging area we use this command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m &amp;lt;&amp;lt;" commit_message"&amp;gt;&amp;gt;
git restore --staged &amp;lt;&amp;lt;nameofthefile&amp;gt;&amp;gt;
git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Command to delete the file (this is the linux command) 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm -rf &amp;lt;&amp;lt;nameofthefile&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Command to delete file in windows is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rm &amp;lt;&amp;lt;nameofthefile&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Command used to unstage the commits or remove the commit just copy past the hasdid of the commit which is just below it, the command is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset &amp;lt;&amp;lt;hashidofthecommit&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· To attach the URL to our project, use the command 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin &amp;lt;&amp;lt;URLOfTheGitRepository&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Command that shows all the URLs attached to the main repository is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote -v
origin https://github.com/AjayTumula/StrugglersInDev-Git.git (fetch)
origin https://github.com/AjayTumula/StrugglersInDev-Git.git (push)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;· Command used to push the changes to the origin URL and the main branch is 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>github</category>
      <category>softwareengineering</category>
      <category>development</category>
    </item>
  </channel>
</rss>
