<?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>DEV Community: Shekhar Ranjan</title>
    <description>The latest articles on DEV Community by Shekhar Ranjan (@shekhar10feb).</description>
    <link>https://dev.to/shekhar10feb</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%2F551610%2F621efa03-344d-4165-8ef6-8b01953b0833.jpg</url>
      <title>DEV Community: Shekhar Ranjan</title>
      <link>https://dev.to/shekhar10feb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shekhar10feb"/>
    <language>en</language>
    <item>
      <title>Get introduced with Git and GitHub</title>
      <dc:creator>Shekhar Ranjan</dc:creator>
      <pubDate>Sat, 02 Jan 2021 08:43:06 +0000</pubDate>
      <link>https://dev.to/shekhar10feb/get-introduced-with-git-and-github-5chg</link>
      <guid>https://dev.to/shekhar10feb/get-introduced-with-git-and-github-5chg</guid>
      <description>&lt;p&gt;Hello friends 👋  😃 , when we talk about &lt;strong&gt;git&lt;/strong&gt; and &lt;strong&gt;github&lt;/strong&gt; then, there are lot of confusion 😕 exist in our mind. Especially, when we talk about their commands. I also encountered with the same issue and mentors helped me and motivate me to face this and gave me some suggestions in order to overcome this. And thanks to the mentors, who suggested me to write an article about it. So, here I am writing about some concepts, which &lt;br&gt;
are related to &lt;strong&gt;github&lt;/strong&gt; and &lt;strong&gt;git&lt;/strong&gt; and some commands(which you can use it in &lt;em&gt;git bash&lt;/em&gt;, &lt;em&gt;cmd&lt;/em&gt; or &lt;em&gt;vscode terminal&lt;/em&gt;) too, which, I hope, would be very &lt;br&gt;
helpful for everyone.&lt;/p&gt;

&lt;p&gt;So, here we are discussing about following terms, which might be very important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Fork&lt;/li&gt;
&lt;li&gt; Branches&lt;/li&gt;
&lt;li&gt; Push commit to a remote repository&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Fork
&lt;/h3&gt;

&lt;p&gt;When we &lt;strong&gt;fork&lt;/strong&gt; a repository, in our case we &lt;strong&gt;fork&lt;/strong&gt; the &lt;strong&gt;&lt;a href="https://github.com/twindle-co/twindle" rel="noopener noreferrer"&gt;Twindle&lt;/a&gt;&lt;/strong&gt; (I have learned a lot and still learning so many things from Twindle) repository  then, we get a personal copy of the repository in our &lt;strong&gt;github&lt;/strong&gt; account, where we are free to make changes without affecting the main project. When we do some changes in our own repository and want to implement these changes in the main project then, we raise pull request(PR). The authority of the main project review the changes and if they think it is good to include this change in the main project then, they add it( you everytime want this to happen ) otherwise, reject it( sorry, but it happens too ). &lt;/p&gt;
&lt;h3&gt;
  
  
  Branches
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Branches&lt;/strong&gt; are almost like a new copy of our code at the current state( it means you forked a repository, which becomes "master" version in your repository and then, you make a copy of your "master" version ), which can then be used to develop new code.For example, whenever we need to create a new feature, or rewrite any of our code, it's a good thing to create a new branch so that none &lt;br&gt;
of our changes affect the "master" version of the code. This is important since it can be very difficult to revert code changes from memory, especially in complex systems. And also there are many changes happen in the "master" version of the main repository like in &lt;strong&gt;Twindle&lt;/strong&gt;, people work on the code and raise PR requests. If we try to raise PR request from our "master" version then, the PR requests raised by the people will also get &lt;br&gt;
added in our raised PR and this creates mess. So, to avoid these problems, we need to create a branch, raise PR request from that branch, this will avoid others' PR requests and &lt;em&gt;when the PR request is approved then, that branch must be deleted.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;First of all, when we are creating a branch using &lt;em&gt;git bash&lt;/em&gt; then, we must assure that we are in the main branch as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99707614-b5f9c880-2ac2-11eb-8fdd-5a6b3bbd2175.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99707614-b5f9c880-2ac2-11eb-8fdd-5a6b3bbd2175.JPG" alt="git9"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, in the above photo, "(main)" shows that we are in the main branch. Now, there are certain commands we should know and these are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To initialize a repository for a new or existing project,
&lt;/li&gt;
&lt;/ul&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;ul&gt;
&lt;li&gt; To create a branch from the current branch
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      git branch &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;this makes a copy of main branch,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99710208-4685d800-2ac6-11eb-9b6b-1f7604abc9e4.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99710208-4685d800-2ac6-11eb-9b6b-1f7604abc9e4.JPG" alt="git10"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; To see how many branches in the git or local,
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    git branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99710273-5bfb0200-2ac6-11eb-9946-dc823f3811a2.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99710273-5bfb0200-2ac6-11eb-9946-dc823f3811a2.JPG" alt="git11"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By seeing the photo, we also conclude that we are in the main branch because of the * .&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; To see all the branches (local as well as remote),
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   git branch -a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99759139-79f15280-2b18-11eb-87d1-8a63767bc8d9.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99759139-79f15280-2b18-11eb-87d1-8a63767bc8d9.JPG" alt="git12"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the above picture, we can see the local as well as remote branches(in red color).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; To switch from current branch to another branch,
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  git checkout &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99766351-ea9f6b80-2b26-11eb-8534-63440b2c6ff0.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99766351-ea9f6b80-2b26-11eb-8534-63440b2c6ff0.JPG" alt="git13"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, first we in main branch, see all branches in the local and then, we switch to another branch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To delete the branch but first, you need to go into the master or main branch then,
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  git branch -d &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99766796-d5770c80-2b27-11eb-8bb6-cdd08c268e5f.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72906055%2F99766796-d5770c80-2b27-11eb-8bb6-cdd08c268e5f.JPG" alt="git14"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And again check how many branches are in your local.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: if it shows error: The branch  is not fully merged then, please use,&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; To add one or more files to staging(index) area,
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; To list the files you have changed and those still need to add or commit,
&lt;/li&gt;
&lt;/ul&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;ul&gt;
&lt;li&gt; To remove files from staging area(unstage),
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; To commit changes to head(here, head means where you are),
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; To see the total commits you have done,
&lt;/li&gt;
&lt;/ul&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;h3&gt;
  
  
  Push commit to a remote repository
&lt;/h3&gt;

&lt;p&gt;Commit means to save your changes in our local repository. When we do commit in the local repository then, we need to push this commit in remote &lt;br&gt;
repository or our github account. We use &lt;code&gt;git push&lt;/code&gt; to push commits to do this.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;git push&lt;/code&gt; command takes two arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A remote name, for example,  &lt;code&gt;origin&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A branch name, for example,  &lt;code&gt;branch1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git push origin branch1&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;then, go to the github account where, we can see a branch of same name is created with the changes we did in the local. From that same branch that is, &lt;br&gt;
branch1, raise pull request. &lt;em&gt;This PR would be clean and without any mess. After approval or rejection, please remove that branch from remote and local.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Suggestions are welcome 😊 !!&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>vscode</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
