<?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: Sabbir Hasan</title>
    <description>The latest articles on DEV Community by Sabbir Hasan (@sabbirshouvo).</description>
    <link>https://dev.to/sabbirshouvo</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%2F733794%2F0966e130-fe64-4921-80c4-b3f12ff87383.jpg</url>
      <title>DEV Community: Sabbir Hasan</title>
      <link>https://dev.to/sabbirshouvo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sabbirshouvo"/>
    <language>en</language>
    <item>
      <title>GIT Basics: A beginners guide!</title>
      <dc:creator>Sabbir Hasan</dc:creator>
      <pubDate>Fri, 13 Jan 2023 12:49:47 +0000</pubDate>
      <link>https://dev.to/sabbirshouvo/git-basics-a-beginners-guide-4a7h</link>
      <guid>https://dev.to/sabbirshouvo/git-basics-a-beginners-guide-4a7h</guid>
      <description>&lt;p&gt;&lt;strong&gt;Git&lt;/strong&gt; is a popular version control system that allows developers to track and manage changes to their code. It is widely used in software development and is considered to be one of the most popular version control systems in use today.&lt;/p&gt;

&lt;p&gt;One of the main benefits of using Git is that it allows developers to &lt;strong&gt;work on the same codebase simultaneously without interfering with each other's work&lt;/strong&gt;. This is achieved by using a branching system, which allows developers to create separate branches of the codebase to work on. Once a developer has completed their work, they can then merge their changes back into the main branch.&lt;/p&gt;

&lt;p&gt;Another benefit of using Git is that it allows for easy collaboration among developers. By using a centralized repository, such as &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;, developers can easily share their code with others and collaborate on projects together.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will go through the basics of Git and how to use it effectively.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Installing Git&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The first step in using Git is to install it on your computer. You can download the latest version of Git from the official website. Once you have downloaded the installer, run it and follow the instructions to install Git on your computer. More detailed instruction can be found here &lt;a href="https://github.com/git-guides/install-git" rel="noopener noreferrer"&gt;https://github.com/git-guides/install-git&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Creating a new repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once you have installed Git, you can create a new repository on your computer by running the command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;in the command prompt. This command will create a new repository in the current directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. Adding files to the repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To add files to your repository, you can use the command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;followed by the file name. For example, to add a file called "index.html", you would run the command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;You can also use the command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;to add all the files in the current directory to the repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4. Committing changes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once you have added your files, you can then commit your changes using the command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;and providing a commit message. The commit message should be a brief description of the changes you have made. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;'Fixed issue that causing layout flickering'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;5. Pushing changes to a remote repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To push your changes to a remote repository, such as GitHub, you can use the command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will upload your changes to the remote repository, allowing others to access them. For example,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;will push your changes to the &lt;code&gt;master&lt;/code&gt; branch of a remote repository named &lt;code&gt;origin&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;6. Downloading changes from a remote repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To download changes from a remote repository, you can use the command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will download any changes that have been made to the remote repository and merge them with your local repository. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will pull any changes from the &lt;code&gt;master&lt;/code&gt; branch of a remote repository named &lt;code&gt;origin&lt;/code&gt; and merge them with your local repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;7. Branching&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Git allows developers to work on separate branches of the codebase simultaneously. To create a new branch, use the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch branch_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and to switch to that branch use the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout branch_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have made changes to the branch and you are ready to merge it with the main branch, you can use the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git merge branch_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the basic commands that you need to know to start using Git effectively. By using Git, you will be able to track and manage changes to your code, collaborate with others, and easily share your code.&lt;/p&gt;

&lt;p&gt;As an example, let's say you are working on a project called &lt;code&gt;MyProject&lt;/code&gt; and you have created a new branch called &lt;code&gt;feature1&lt;/code&gt; to work on a new feature. To create the branch and switch to it, you would run the commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch feature1
git checkout feature1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You make some changes to the code, add the files and commit the changes with the commit message "added feature1"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;'added feature1'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you are ready to merge the changes to the main branch, you switch to the main branch and merge feature1 branch&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout master
git merge feature1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;8. Cloning a repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Another way to access a remote repository is by cloning it. Cloning a repository will create a copy of the remote repository on your local machine, allowing you to work on the code locally. You can use the command &lt;code&gt;git clone&lt;/code&gt; followed by the repository URL to clone a repository. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/user/MyProject.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will clone the &lt;code&gt;MyProject&lt;/code&gt; repository from the GitHub user's account.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;9. Checking the status of the repository&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can use the command &lt;code&gt;git status&lt;/code&gt; to check the status of your repository. This command will show you which files have been modified, added, or deleted and which branch you are currently working on.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;10. Viewing the commit history&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can use the command &lt;code&gt;git log&lt;/code&gt; to view the commit history of your repository. This command will show you a list of all the commits that have been made, along with the commit message, author, and date.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;11. Reverting changes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you need to revert changes that you have made, you can use the command &lt;code&gt;git revert&lt;/code&gt;. This command will undo the changes made in a specific commit and create a new commit with the changes. You can also use the command &lt;code&gt;git reset&lt;/code&gt; to remove commits from the repository.&lt;/p&gt;




&lt;p&gt;Git is a powerful version control system that can help you to track and manage changes to your code. By using Git, you can work on the same codebase simultaneously, collaborate with others, and easily share your code. In this tutorial, we have covered the basics of Git and how to use it effectively. Remember to keep your commits small and focused, and always use meaningful commit messages.&lt;/p&gt;




&lt;h3&gt;
  
  
  Key takeouts
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Git is a tool that helps you keep track of the changes you make to your code. It allows you to save different versions of your code and easily switch between them.&lt;/li&gt;
&lt;li&gt;Git also allows you to work on the same code with other people. You can make changes to your own copy of the code, and then merge those changes with the version that everyone else is working on.&lt;/li&gt;
&lt;li&gt;To start using Git, you will need to download and install it on your computer, then you can create a new "repository" to store your code. To save changes to your code, you will use the basic Git commands like "git add" and "git commit".&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>productivity</category>
      <category>discuss</category>
      <category>career</category>
    </item>
    <item>
      <title>Multiple git profiles without manually switching the config</title>
      <dc:creator>Sabbir Hasan</dc:creator>
      <pubDate>Wed, 04 Jan 2023 16:05:41 +0000</pubDate>
      <link>https://dev.to/sabbirshouvo/multiple-git-profile-without-manually-switching-the-config-3087</link>
      <guid>https://dev.to/sabbirshouvo/multiple-git-profile-without-manually-switching-the-config-3087</guid>
      <description>&lt;p&gt;We often need to maintain multiple git client. For myself I use Github for my personal work and bitbucket for job. In a single device it's a bit painful to maintain if you don't create separate user account for personal and job works.&lt;/p&gt;

&lt;p&gt;I used to override the local &lt;code&gt;.git/config&lt;/code&gt; for my personal projects while leaving the &lt;code&gt;--global&lt;/code&gt; config for bitbucket. &lt;/p&gt;

&lt;p&gt;But today I'll share a trick that will help you to handle this situation automatically! In order to do this your git version must be above &lt;code&gt;2.13&lt;/code&gt;. Let's check that first.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;My git version is &lt;code&gt;2.38.1&lt;/code&gt;. So this trick will work for me. You can continue following this guide if your git version is larger than &lt;code&gt;2.13&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;Let's say you follow this file structure for your projects&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/
-- Personal/
---- Project A
---- Project B
-- Work/
---- Project A
---- Project B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you separately store you personal and work repositories then you are already a step ahead! If not then start by doing this first.&lt;/p&gt;

&lt;p&gt;Once you have separated you repositories, let's look at the git config file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat ~/.gitconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It may look like this if don't have anything but &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;email&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[user]
    name = user_name
    email = user@gmail.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's create two new files for personal and work profiles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch ~/.gitconfig_personal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch ~/.gitconfig_work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and open them in your favorite text editor. In my case VS Code.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Now copy the content of &lt;code&gt;~/.gitconfig&lt;/code&gt; and modify as needed. After that save the file. Do same for the other config file.&lt;/p&gt;

&lt;p&gt;Once done, let's open the &lt;code&gt;~/.gitconfig&lt;/code&gt; file in VS Code and add necessary changes to the files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[includeIf "gitdir:~/Personal/"]
  path = .gitconfig_personal
[includeIf "gitdir:~/Work/"]
  path = .gitconfig_work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above code will allow you to conditionally include configs based on the directory. &lt;/p&gt;

&lt;p&gt;You still will be able to override this using &lt;code&gt;git config&lt;/code&gt; for specific repository.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
