πŸš€Day 9 Task: Deep Dive in Git & GitHub for DevOps Engineers.

Β·

9 min read


πŸ‘‰πŸΌ What is Git and why is it important?

Git is a distributed version control system (VCS). It's designed to manage and track changes to source code, allowing multiple contributors to collaborate on a project while maintaining a history of all changes made over time.

Here's why Git is important:

  1. Version Control: Git allows developers to track changes to their codebase over time. This enables them to revert to previous versions of the code, identify when and by whom specific changes were made, and collaborate on code without fear of losing work.

  2. Collaboration: Git facilitates collaborative development by enabling multiple developers to work on the same project simultaneously. Each developer can make changes in their own "branch" of the code, and these changes can be merged when they are ready.

  3. Branching and Merging: Git allows for easy branching, which means creating separate lines of development that can be worked on independently. This is valuable for trying out new features, fixing bugs, or experimenting without affecting the main codebase. Merging allows these separate branches to be combined once their changes are ready.

  4. Code History: Git maintains a complete history of all changes made to the codebase. This is valuable for understanding how the project has evolved, tracking down the source of bugs, and reviewing the work of contributors.

  5. Backup and Recovery: With a distributed VCS like Git, every contributor has a complete copy of the repository. This provides a form of backup, reducing the risk of data loss. If a central server goes down, developers can continue working using their local copies and later synchronize their changes when the server is back online.

  6. Open Source Development: Git has been widely adopted by the open-source community, making it easier for people from around the world to contribute to projects. Platforms like GitHub, GitLab, and Bitbucket provide a space for hosting Git repositories and facilitating collaboration.

  7. Facilitates Code Reviews: Git's branching and merging capabilities make it easier to conduct code reviews. Developers can create pull requests or merge requests, allowing others to review changes before they are merged into the main codebase.

  8. Workflow Flexibility: Git doesn't enforce a strict workflow, allowing teams to adopt processes that suit their needs. Different branching strategies, like Gitflow or GitHub Flow, can be used to manage development.


πŸ‘‰πŸΌ What is the difference Between Main Branch and Master Branch?

Master BranchMain Branch
Historically, the default branch in many Git repositories was named "master." This term was widely used and has its origins in the early days of version control systems. However, in recent years, there has been a growing awareness of the term's association with slavery and its negative connotations. As a result, there has been a movement within the tech community to replace "master" with more neutral terminology.In response to concerns about the term "master," many projects and organizations have started to use "main" as the default branch name instead. The term "main" is seen as a more inclusive and neutral alternative, avoiding any potential negative associations.

πŸ“•The main difference between the "main branch" and the "master branch" is primarily the terminology used to refer to the default branch in a Git repository. The concept and functionality of the default branch remain the same regardless of whether it's called "main" or "master." It serves as the starting point for the development of a project, and other branches can be created and merged from it.


πŸ‘‰πŸΌ What is the difference between Git and GitHub?

GitGit Hub
Git is a distributed version control system (VCS) that allows developers to track changes to their source code over time.GitHub is a web-based platform that provides hosting services for Git repositories.
Git allows developers to create branches for different lines of development, merge changes back together, and maintain a complete history of all changes made to the codebase.It allows developers to store their Git repositories remotely and provides a variety of collaboration and management tools.
It operates locally on a developer's machine, meaning that each developer has a complete copy of the entire repository, including its history.It fosters collaboration among developers, making it easier for teams to work together on projects, contribute to open-source projects, and manage their software development workflows.
Developers can work with Git through the command line interface (CLI) and execute commands like git commit, git branch, and git merge.GitHub provides features like pull requests, issue tracking, code reviews, and project management tools.
Git is a command line tool.GitHub adds a graphical user interface (GUI) layer on top of Git, making it more accessible to users who might not be as comfortable with the command line.

πŸ“•Git is the core technology that handles version control, change tracking, and collaboration within a codebase, and it operates locally on a developer's machine. On the other hand, GitHub is a web-based platform that provides tools for hosting Git repositories remotely, facilitating collaboration, and enhancing the software development workflow. While Git is essential for version control, GitHub enhances collaboration by providing features and tools to streamline the process of working with Git repositories in a team setting.


πŸ‘‰πŸΌ How do you create a new repository on GitHub?

Steps:

  1. Sign in to GitHub: If you don't have an account, you'll need to sign up for one. If you already have an account, log in.

  1. Access Your Dashboard: Once you're logged in, you'll be taken to your dashboard. If you're on the GitHub homepage, you can click on your profile picture in the top right corner and then select "Your repositories" to access your repositories.

  1. Create a New Repository: On the "Your repositories" page, click the green "New" button located on the right side.

  2. Set Up Repository Options: You'll be taken to the "Create a new repository" page. Here, you'll need to provide some information:

  • Repository Name: Enter a name for your repository.

  • Description: Optionally, provide a brief description of your project.

  • Visibility: Choose whether your repository should be public (visible to everyone) or private (visible only to you and collaborators you invite).

  • Initialize this repository with a README: If you select this option, GitHub will automatically create a README file in the repository. This is helpful to provide an initial overview of your project.

  • Add .gitignore: You can select a template for your project's .gitignore file. This helps exclude specific files or directories from being tracked by Git.

  • Add a license: You can choose a license for your project to specify how others can use your code.

  1. Create Repository: Once you've filled in the necessary information, click the green "Create Repository" button.

  2. Once you click "Create Repository" go to the dashboard and check your repository.


πŸ‘‰πŸΌ What is the difference between local & remote repositories?

LocalRemote
A local repository is the version of your project that resides on your local computer or development environment.A remote repository is a version of your project hosted on a remote server, often on platforms like GitHub, GitLab, or Bitbucket.
It contains all project files, directories, and the entire history of changes (commits) made to the project.Remote repositories serve as central hubs for collaboration and backups. They can be accessed by multiple developers from different locations.
Developers work directly with the files in their local repository, making changes, adding new files, and committing their work.Remote repositories store the same version history and files as your local repository.
A local repository provides a safe space to experiment, develop, and test code changes without affecting other contributors or the shared codebase.Changes made in the local repository need to be pushed to the remote repository to make them visible to others and to keep the remote repository up to date.

πŸ‘‰πŸΌHow to connect local to remote?

Connecting Local to Remote Repository: To connect your local repository to a remote repository, follow these steps using GitHub as an example:

  1. Create a Remote Repository on GitHub

  2. Copy Remote Repository URL: On your GitHub repository page, click the "Code" button to reveal the repository's URL. You can choose between HTTPS or SSH, depending on your authentication preferences.

Add Remote Origin: In your local repository, open a terminal or command prompt and navigate to the repository's directory. Then, use this command to add the remote repository URL as the "origin":

git remote add origin <remote_repository_url>

Replace <remote_repository_url> with the actual URL you copied.

πŸ“•Now, your local repository is connected to the remote repository. You can use Git commands like git pull and git push to sync your work between local and remote repositories. For HTTPS, you'll need to authenticate with your remote repository (GitHub); for SSH, ensure you've set up SSH keys for authentication.


πŸ“šTasks

Task 1: Set your user name and email address, which will be associated with your commits.

Setting User Name: Open a terminal or command prompt and use the following command to set your user name:

git config --global user.name "nikul"

Setting Email Address: Use the following command to set your email address:

git config --global user.email "youremail@example.com"

Task 2:

  1. Create a repository named "Devops" on GitHub

    Solution: Check the above section πŸ‘‰πŸΌ How do you create a new repository on GitHub

  2. Connect your local repository to the repository on GitHub.

    Solution: Check the above section πŸ‘‰πŸΌHow to connect local to remote?

  3. Create a new file in Devops/Git/Day-02.txt & add some content to it

added content to Day-02.txt

Push your local commits to the repository on Git.

git add Day-02.txt
git commit -m "added content"
git push origin main

🌟 Conclusion:

Congratulations! πŸŽ‰

Git is an essential tool βš™οΈ for developers πŸ‘¨πŸ»β€πŸ’»to manage their code, collaborate effectively, and maintain a detailed record of their project's development history. It's widely used across the software industry and has become a standard tool for version control and collaborative coding.

GitHub 😸 is a web-based platform where developers can collaborate, contribute, and showcase their coding skills.

We hope this blog has given you a Question/Answer πŸš€πŸ’ͺ

πŸ” Did you find this blog helpful? Let us know in the comments below! πŸ‘‡ And if you have any questions or need further assistance, we're here to help! πŸ€—

Happy Learning! πŸ’»βœ¨

Β