#Day9-Deep Dive 🏊‍♂️in Git & GitHub for DevOps Engineers🥽.

Sneha FalmariSneha Falmari
6 min read

🌷What is Git and why is it important?

Git is a distributed version control system that helps developers track changes in their code over time. It keeps a copy of the old version of the file. Git allows collaboration and also we can track different versions.

🍃Git is important for several reasons:

  1. Version Control: Git allows developers to maintain a history of changes made to their codebase, making it easy to track who made what changes and when. This helps in debugging, collaboration, and maintaining a stable codebase.

  2. Collaboration: With Git, multiple developers can work on the same project simultaneously without interfering with each other's work. It enables seamless collaboration, as changes can be merged together.

  3. Branching and Merging: Git's branching and merging capabilities allow developers to create isolated environments (branches) to work on new features or bug fixes without affecting the main codebase. When the changes are ready, they can be merged back into the main branch.

  4. Backup and Recovery: Git repositories act as backups of your code, ensuring that your work is safe even if your local machine experiences issues.

  5. Open Source Community: Many open-source projects use Git, making it easier for developers to contribute to and benefit from community-driven software development.

🌷What is the difference Between Main Branch and Master Branch?

In Git, the terms "Main Branch" and "Master Branch" refer to the default branch in a repository. Git is used "master" as the default branch name. Historically, "master" was the default name given to the primary branch in Git. However, some developers and organizations have recognized that the term "master" may have potential associations with slavery, which is why there has been a movement to replace it with more neutral and inclusive terms.

So, there is no functional difference between the two terms. They both represent the primary branch where the latest codebase is stored.

🌷Explain the difference between Git and GitHub?

🐙Git🦑Github
Git is a distributed version control system.GitHub is a web-based hosting service that utilizes Git for version control
Used by developers to manage and track changes in their codebase.one of the most popular platforms for hosting Git repositories and collaborating on software projects
Key features of Git include: Distributed, Commits, Branching and Merging, History and Time Travel.Key features of GitHub include: Remote Repository Hosting, Collaboration and Pull Requests, Issue Tracking and Project Management, and Community and Social Features.
Developers can use Git without GitHub.But GitHub leverages the power of Git to enable efficient collaboration and project management for software development teams.

🌷How to create a new repository on GitHub?

  1. Go to https://github.com/ and sign in to your GitHub account. If you don't have an account, you'll need to create one first.

  2. Once you are signed in, click on the + icon in the top-right corner of the GitHub page. From the dropdown menu, select "New repository."

  3. You will be taken to the "Create a new repository" page. Here, you'll need to provide some information about your new repository:

    • Repository Name: Choose a unique and descriptive name for your repository.

    • Description: Optionally, you can add a brief description of what your repository is about.

    • Visibility: Choose whether your repository will be public (visible to everyone) or private (visible only to you and collaborators). Private repositories require a paid GitHub subscription.

    • Initialize this repository with a README: If you want to start your repository with a README file (recommended), check this option.

  4. Below the initial configuration, you have a few optional settings to choose from:

    • Add .gitignore: You can choose a template for .gitignore to automatically exclude certain files from version control. Select the appropriate template based on your project's programming language and environment.

    • Add a license: You can choose an open-source license for your project if desired. If you're unsure, it's best to consult with your team or community about the appropriate license.

  5. After configuring the repository options, click the green "Create repository" button at the bottom of the page. Your new repository will now be created and ready to use.

  6. If you already have a local project on your computer that you want to link to the new repository, you'll need to set up a remote link. In your local project directory, open a terminal or command prompt and run the following commands:

git init   # Initializes a new Git repository locally, if you haven't done so already.
git remote add origin <repository-url>
git add .
git commit -m "Initial commit"
git push -u origin master

Replace <repository-url> with the URL of your newly created GitHub repository. This will link your local project to the remote repository on GitHub.

🌷What is the difference between local & remote repositories? How to connect local to remote?

🍃Local Repository: A local repository exists on your local computer and contains the entire version history of your project. When you initialize a Git repository on your computer (using git init), it creates a local repository. All the files, commits, branches, and history are stored locally. You can make changes, create branches, commit changes, and view the project history without the need for an internet connection or interaction with external servers.

🍃Remote Repository: A remote repository exists on a remote server, such as GitHub, GitLab, Bitbucket, or any other Git hosting service. It serves as a central point of collaboration for multiple developers working on the same project. The remote repository is typically the "origin" repository, and developers push and pull changes from it to synchronize their work with others.

🍃Steps to connect local to remote:

Connecting the local repository to the remote repository is a two-step process: adding a remote and pushing to the remote.

  • To connect your local repository to a remote repository, you need to add the remote URL using the following command:
git remote add origin <remote-url>

Replace <remote-url> with the URL of your remote repository. The "origin" is the conventional name for the remote, but you can choose a different name if you wish.

  • After adding the remote, you can push your local repository's changes to the remote using the following command:
git push -u origin master

Here, master is the name of the branch you want to push. If you have a different main branch (ex. main, develop), use that branch's name instead.

The -u flag sets the upstream branch, allowing you to use git push in the future without specifying the remote and branch name.

Once you have set up the connection between your local and remote repositories, you can push your changes to the remote using git push and pull changes from the remote using git pull. This synchronization process helps you collaborate with other developers, share your work, and keep everyone up to date with the latest changes in the project.

🌷Conclusion :

Congratulations! You're now well-equipped to understand the difference between Git and GitHub, create new repositories, and connect 🔗 your local work to remote repositories📂. Embrace the power of version control and collaboration as you embark on your coding journey🚶‍♀️!

Happy coding!✨

6
Subscribe to my newsletter

Read articles from Sneha Falmari directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sneha Falmari
Sneha Falmari