<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kushantha Sajith Lakshan on Medium]]></title>
        <description><![CDATA[Stories by Kushantha Sajith Lakshan on Medium]]></description>
        <link>https://medium.com/@kushanthasajith?source=rss-b83bca98318a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*C6jVvSH9DP-MImhwF8GA8A.png</url>
            <title>Stories by Kushantha Sajith Lakshan on Medium</title>
            <link>https://medium.com/@kushanthasajith?source=rss-b83bca98318a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:04:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kushanthasajith/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Git and GitHub for Beginners: Your First Repository]]></title>
            <link>https://kushanthasajith.medium.com/git-and-github-for-beginners-your-first-repository-c5241a0887b5?source=rss-b83bca98318a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5241a0887b5</guid>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Kushantha Sajith Lakshan]]></dc:creator>
            <pubDate>Sun, 23 Jul 2023 06:19:51 GMT</pubDate>
            <atom:updated>2023-07-23T06:19:51.033Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi all, Welcome to my first-ever article! I am thrilled to share with you the exciting world of Git and GitHub, a must-know for any aspiring developer or programmer. If you’ve just started your journey in the world of coding, chances are you might have already heard about these powerful tools. In this beginner’s guide, we’ll walk through the process of setting up Git and GitHub from scratch and creating your first repository step-by-step. By the end of this article, you’ll have a solid foundation to manage your projects efficiently and collaborate with others like a pro.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*cI4Qhh12GykdyDo5.png" /></figure><p>Git, the version control system, helps you track changes in your code and collaborate seamlessly with others. GitHub, on the other hand, provides a platform for hosting your repositories remotely, opening the doors to collaborative development and showcasing your projects to the world. Together, they form an unbeatable duo that will streamline your development workflow and empower you to tackle projects of any size.</p><p>So, if you’re ready to embark on this enriching learning journey, grab your coding gear, and let’s configure Git, initialize a local repository, and push it to GitHub. By the end of this article, you’ll be confidently navigating the world of version control and sharing your projects with the global developer community. Let’s dive in and get started with Git and GitHub for beginners!</p><h3>Step 1 — Creating a GitHub Account</h3><p>Let’s start with creating a new GitHub account. If you already have a GitHub account, you can skip this step and continue with the next step.</p><p>First, go to the GitHub website —<em> </em><a href="https://github.com/"><em>github.com</em></a> — in your web browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*asx8JOFjzwImyZiTnE5shw.png" /></figure><p>Click on the “<strong>Sign Up</strong>” button, and then fill in the required information, such as your username, email address, and password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*-KEtrkRQwuMqRsKMk9na9g.png" /></figure><p>Next, you’ll receive a code in your email address. Enter the code into the provided field. If you didn’t receive the code, make sure to check your spam folder. If it’s not there, you can click on “<strong>Resend the Code</strong>” to get a new one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*E2-6lMgMrcHUHSt3yMrsmQ.png" /></figure><p>After entering the code, you’ll be taken to a screen asking for some additional information. It’s up to you whether you want to skip it or fill it out. Then you will reach to the dashboard, which will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cei_eWh9cFKung5_iTJLeQ.png" /></figure><p>Congratulations! You have successfully created your GitHub account. You can now start using GitHub to collaborate, host your projects, and explore the world of open-source software.</p><p>Remember to keep your GitHub account credentials safe and consider enabling two-factor authentication for added security. With your GitHub account set up, you’re all set to start making contributions, hosting your repositories, and collaborating with other developers.</p><h3>Step 2 — Installing Git</h3><p>Git is available for multiple operating systems, making it accessible to developers using Windows, macOS, and Linux. Let’s walk through the installation process for each platform and then verify the installation by running a simple Git command.</p><h4>Installing Git on Windows:</h4><p>Visit the official Git website: <a href="https://git-scm.com/"><em>https://git-scm.com/</em></a> Click on the “Download for Windows” button to download the installer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*oxTy1A2hueSVrdJ1S7D16Q.png" /></figure><p>Once the download is complete, open the installer. Follow the on-screen instructions and choose the appropriate options during the installation process (the default options are usually sufficient).</p><p>After the installation is complete, open the Windows Command Prompt or Git Bash (included with the Git installation) and type the following command to verify the installation.</p><pre>git --version</pre><p>Then you can see something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*eVVHUhECl0Z-V18RinxOdQ.png" /></figure><p>If you encounter any issues, wait a couple of minutes and try again. If the problem persists, you can search for solutions on the internet.</p><h4>Installing Git on macOS:</h4><p>Git comes pre-installed on macOS. However, it’s a good practice to use the latest version. To check if Git is installed, open the Terminal and enter the following command:</p><pre>git --version</pre><p>If Git is not installed, macOS will prompt you to install the Xcode Command Line Tools, which includes Git.</p><h4>Installing Git on Linux:</h4><p>For Debian/Ubuntu-based distributions, open the terminal and use the package manager to install Git:</p><pre>sudo apt-get update<br>sudo apt-get install git</pre><p>Now that Git is installed, we’re ready to start utilizing its powerful version control capabilities. In the following sections, we’ll walk through the steps to initialize a local repository, make commits, and push your code to GitHub. Let’s continue the journey into the world of Git and GitHub!</p><h3>Step 3— Setting Up Git Configuration</h3><p>Configuring your username and email in Git is essential as it allows Git to associate your commits with your identity accurately. Each commit you make includes this information, making it crucial for proper attribution and collaboration. Let’s explore how to set up the global Git configuration using the git config command.</p><h4>Importance of Configuring Username and Email:</h4><p>When you make a commit in Git, it records not only the changes you’ve made but also the author of the changes. This author information is vital for tracking contributions, understanding who made specific changes, and facilitating collaboration among team members. Without setting up your username and email, your commits will lack this crucial identification, making it challenging for others to know who made what changes.</p><h4>Setting Up Global Git Configuration:</h4><p>Open your terminal or command prompt, and follow these steps to set up your global Git configuration:</p><pre>git config --global user.name &quot;Your Name&quot;<br>git config --global user.email &quot;youremail@example.com&quot;</pre><p>For example, I would enter:</p><pre>git config --global user.name &quot;Kushantha&quot;<br>git config --global user.email &quot;kushantha018@gmail.com&quot;</pre><p>Replace your own name and email address accordingly.</p><p>And also, you can config git by editing global git configuration file.</p><pre>git config --global --edit</pre><p>It opens the global Git configuration file in your default text editor, allowing you to easily modify or add settings like your name, email, default text editor for commit messages, and more. This file contains settings that apply globally to all Git repositories on your computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Onac-r53Fak0OvrONiIFQ.png" /></figure><p>By using this command, you avoid the need to manually locate and edit the configuration file. Instead, you can make changes directly in the text editor, which is a more user-friendly and efficient way to manage your Git settings.</p><p>Setting up your username and email is a one-time process that ensures your contributions are well-documented and attributed accurately. With your Git configuration in place, you’re ready to start making commits to your local repositories and collaborating with others using Git and GitHub. In the next section, we’ll explore how to initialize a local repository and make your first commit. Let’s continue our journey into version control with Git and GitHub!</p><h3>Step 4— Initializing a Local Repository</h3><h4>What is a Local Git Repository and Why is it Useful?</h4><p>A local Git repository is a self-contained version control environment that resides on your computer. It allows you to track changes, manage different versions of your code, and collaborate with others without the need for a constant internet connection. Having a local repository is incredibly valuable because it empowers you to work on your projects offline, experiment with new features, and maintain a complete history of your codebase — all while benefiting from Git’s powerful version control capabilities.</p><h4>Creating a Local Git Repository:</h4><p>To set up a local Git repository, first, you need to create a Project folder. You can do this through your computer’s file explorer or by using the terminal/command prompt:</p><pre>mkdir my_project<br>cd my_project</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*-drV2uKy6O4-IidgHfTN7w.png" /></figure><p>Replace “my_project” with the desired name for your project directory.</p><p>Now that you’re inside your project directory, it’s time to initialize the Git repository:</p><pre>git init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*8a4M48F6UsF45cKo9aYk5g.png" /></figure><p>Running this command creates a hidden .git directory in your project folder, which contains all the necessary information for version control. Your project is now officially a Git repository!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*GXRvSofnLymgkEnN1b7yqQ.png" /></figure><p>After initializing the repository, you can start adding and committing files to track changes. For example, I will create a file named index.html that include in the repository.</p><h4>Git Status</h4><pre>git status</pre><p>The git status command will show you the current state of your local Git repository. It will provide information about any changes you&#39;ve made to files in your working directory that have not yet been staged (i.e., added to the staging area) for the next commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*LeBBSUMYYDOmUV7N7J_RqA.png" /></figure><p>Now you have a local Git repository set up and ready to track changes for your project. As you continue working on your code, Git will help you manage revisions, collaborate with others, and maintain a detailed history of your project’s development. In the next section, we’ll explore how to add and commit changes efficiently using Git. Let’s keep moving forward with our Git and GitHub journey!</p><h3>Step 5— Adding and Committing Changes</h3><h4>Understanding the Staging Area/Index and Its Role in Committing Changes</h4><p>The staging area, also known as the index, is a fundamental concept in Git that acts as a middle ground between your working directory and the committed history. When you make changes to your project files, these changes are initially in the working directory. However, Git doesn’t automatically include all these changes in the next commit. Instead, you selectively add specific changes to the staging area before committing them.</p><p>This separation allows you to control which changes are part of your next commit. You can make multiple changes across different files but choose to group related changes together in separate commits. This level of granularity provides clarity to your commit history and makes it easier to track and manage changes over time.</p><h4>Adding Files to the Staging Area:</h4><p>To add files to the staging area, you use the git add command. Here&#39;s how you can do it:</p><pre>git add &lt;filename&gt;</pre><p>This command will add a specific file to the staging area.</p><pre>git add .</pre><p>This command will add all the files in the current directory to the staging area. Using “<strong>git add .</strong>” is more convenient, as it includes all the files in the current directory.</p><p>Once you have added the desired changes to the staging area, you are ready to commit them. Committing is like taking a snapshot of the changes in the staging area and permanently recording them in your repository’s history.</p><p>Let’s recheck the status of the local git repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*94Y3-W7TusYmW4_pgHDzYA.png" /></figure><p>After running the git add command, the git status command will show you the updated status of your local Git repository. Specifically, it will display the changes you have staged (i.e., added to the staging area) and those that are ready to be committed in the next commit.</p><p>To commit the changes with a descriptive message, use the git commit command:</p><pre>git commit -m &quot;Your message&quot;</pre><p>You can replace “Your Message” with any message you want. For example, I will type “Initial Commit” as the message.</p><p>You’ll see a message confirming the commit, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*cyWqapiH39wmdSenjTdB1A.png" /></figure><h3>Best Practices for Commits:</h3><ul><li>Commit frequently: Make small, focused commits that capture individual changes or features.</li><li>Write clear commit messages: Be descriptive and concise, using present tense to describe what the commit accomplishes.</li><li>Review your changes before committing: Use git status to review which files will be included in the commit and ensure everything is as expected.</li></ul><h3>Step 6— Creating a Repository on GitHub</h3><p>Let’s start to create a new repository. I’ll demonstrate these steps using my actual GitHub account, so don’t worry if it looks a little different. This is what my Dashboard looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SFQaUp9jGNFH8lLllp9dHA.png" /></figure><p>Click on the “+” sign in the top right corner of the GitHub homepage and select “New Repository” from the drop-down menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*xp4qfTNwS-VQtzQSqOv_2w.png" /></figure><p>After clicking on “<strong>New Repository</strong>”, you’ll be taken to a screen that looks like the one below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tarTdjfjdbX3BoDumoLaRw.png" /></figure><p>Choose a name for your repository. The name should be meaningful and reflective of your project. If you want, you can provide a description for it too. Keep the project public, but if you’re working on any personal projects, you can make it private. Don’t tick the box that says, “<strong>Add a README file</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*LLxfw59g-UMMBpaVAo9E1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*dJsjSxhwX86qGeaO2H0buA.png" /></figure><p>Leave the rest as default settings, and when you’re ready, click on “<strong>Create Repository</strong>”. Congratulations! You have successfully created a new repository on GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1F0YeKDTXJrmW-U4b9NDkQ.png" /></figure><p>Now, you’ll need to connect your local repository to this remote repository to start pushing and pulling changes. In the next section, we’ll cover linking your local repository to GitHub and pushing your code to the remote repository. Let’s continue our Git and GitHub journey!</p><h3>Step 7— Linking Local Repository to GitHub</h3><h4>Adding the GitHub Repository URL as a Remote</h4><p>Now that you have created a new repository on GitHub, the next step is to connect it to your local repository. To achieve this, we’ll use the git remote add command. The term &quot;origin&quot; will be used as an alias to represent the remote repository.</p><p>Go to your GitHub repository’s main page. Click on the green “Code” button, and you’ll see the repository URL. Make sure you choose the HTTPS or SSH URL, depending on your preference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*GMzqaVD-kpAMs8QhxC_xDg.png" /></figure><p>In your terminal or command prompt, navigate to your local repository directory. Then, use the git remote add command with &quot;origin&quot; as the alias and the repository URL you copied from GitHub:</p><pre>git remote add origin &lt;repository URL&gt;</pre><p>For example, I would enter,</p><pre>git remote add origin https://github.com/kushantha-sajith/my_project.git</pre><p>Before pushing to the GitHub repository, we need to change our branch name. The command git branch -M main is typically used to rename the current branch to &quot;main&quot; from &quot;master.&quot; This change in branch name is not mandatory, but it has become a common practice for several reasons, particularly in the context of promoting inclusivity and cultural sensitivity in the software development community.</p><p>If you are already working in the main branch, you can skip this part.</p><pre>git branch -M main</pre><p>In Git, “origin” is a conventional name used to refer to the default remote repository when you clone or initialize a repository. It serves as a convenient way to identify the primary remote repository to which your local repository is linked.</p><p>By linking your local repository to GitHub through the “origin” alias, you can effortlessly push your changes to the remote repository and pull updates from it. The remote repository acts as a bridge between your local development environment and the collaborative space on GitHub, enabling you to share your code with the world and work seamlessly with other developers. In the next section, we’ll cover how to push your local repository to GitHub, making your project accessible to others. Let’s continue our Git and GitHub journey!</p><h3>Step 8 — Pushing Local Repository to GitHub</h3><p>Now that your local repository is connected to the remote repository on GitHub, it’s time to push your code and make it accessible to others. We’ll use the git push command along with the -u flag to achieve this.</p><p>Assuming you are working with the “main” branch, use the following command to push your local repository to GitHub:</p><pre>git push -u origin main</pre><p>If it’s your first time pushing to a remote repository, you’ll be asked to authenticate your login.</p><p>The -u flag is used here to set the default upstream branch for future pushes. It tells Git to remember the relationship between the local branch (main) and the remote branch (origin/main). This way, in future git push commands, you can simply use git push without specifying the branch, and Git will automatically push changes to the corresponding remote branch.</p><p>If you are working on a different branch (e.g., a feature branch), you can push it to GitHub using a similar command:</p><pre>git push -u origin your_branch_name</pre><p>Just replace “your_branch_name” with the actual name of your branch.</p><h4>The Role of the -u Flag</h4><p>The -u flag, also known as --set-upstream, plays a crucial role in setting the default upstream branch for future pushes. When you use -u with the git push command, Git creates a link between the local branch and the corresponding remote branch.</p><p>Once this link is established, you can use git push without specifying the remote branch&#39;s name. Instead, Git will assume you want to push to the upstream branch you set earlier with the -u flag.</p><p>For example, after pushing the main branch using git push -u origin main, you can later make changes and simply use git push to send your commits to the main branch on GitHub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*KXQQxkjIW_XxgmUD1GwXCw.png" /></figure><p>Setting the default upstream branch using the -u flag is particularly helpful for streamlining your workflow. It saves you from having to type out the remote branch name every time you push, reducing the risk of pushing code to the wrong branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VZgm2NrC2fsQU5YcHQx4NQ.png" /></figure><p>Congratulations! Your local repository is now on GitHub, and you’ve successfully pushed your code. Your project is now available on GitHub for collaboration with others and is safely backed up in the remote repository.</p><p>As you continue your developer journey, remember that mastering Git and GitHub is an ongoing process. Embrace their power to enhance your development workflow and promote collaborative coding. Explore advanced features, like branching, pull requests, and issue tracking, to further streamline your projects and engage with the open-source community.</p><p>Don’t be discouraged by initial challenges — every developer, no matter their experience, has faced them. Reach out to online resources, tutorials, and communities to seek support and expand your knowledge. By honing your version control skills, you’ll become a more efficient and confident developer, ready to tackle exciting projects and contribute to the world of software development.</p><p>That’s a warp for my first article, if you found this article helpful, don’t hesitate to share your thoughts and experiences with me. Connect with me on <a href="https://github.com/kushantha-sajith">GitHub</a> and <a href="https://www.linkedin.com/in/kushantha-sajith/">LinkedIn</a> to stay updated with my latest projects, articles, and discussions related to software development.</p><p>Happy coding and may your journey with Git and GitHub be a rewarding one!</p><p>Feel free to follow me on social media:</p><p><em>LinkedIn — </em><a href="https://www.linkedin.com/in/kushantha-sajith/"><em>https://www.linkedin.com/in/kushantha-sajith/</em></a></p><p><em>GitHub — </em><a href="https://github.com/kushantha-sajith"><em>https://github.com/kushantha-sajith</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5241a0887b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>