Day- 8 : Git & GitHub for DevOps Engineers

Day- 8 : Git & GitHub for DevOps Engineers

Β·

8 min read

🌟 Introduction 🌟

Welcome to Day 8 of the thrilling #90DaysOfDevOps challenge! Today, we're diving into the exciting world of Git and GitHub. πŸš€ Unleash the power of version control as we explore the magic of Git and its significance in software development. Discover the wonders of GitHub, where collaboration and sharing come to life. πŸ“š In this blog, we'll unveil the beauty of distributed version control and its advantages over centralized systems. Let's get hands-on by installing Git, creating a GitHub account, and mastering repository creation and cloning. πŸ’»πŸ™ Are you ready to level up your DevOps journey with Git and GitHub? Let's embark on this incredible adventure together! 🌟

πŸ’Ύ What is Git?

Git is a distributed version control system that helps developers track and manage changes to their code during software development. Imagine Git as a time machine that allows you to save snapshots of your project at different points in time. This way, you can go back to any previous state if something goes wrong or if you want to check the history of your code. πŸ’ΎπŸ•°οΈ

Let's dive into a real-time example to grasp Git better. Imagine you're working on a group project with teammates, each responsible for different code parts. Without Git, challenges arise:

  1. Overwriting Changes: Concurrent edits to the same file may overwrite work, causing conflicts and data loss. πŸ˜¬πŸ”„

  2. Tracking Changes: It's tough to monitor who altered what and when hampering progress and bug tracking. πŸ“πŸ”

  3. Collaboration Complexity: Coordinating changes becomes daunting with a shared codebase. πŸ€πŸ—‚οΈ

In summary, Git streamlines collaboration tracks changes effortlessly, and manages code history, making it a must-have tool for developers and projects of all scales. πŸš€πŸ’»

🀝 What is GitHub?

GitHub is a web-based platform and service that helps developers collaborate on coding projects and manage their source code. It provides a user-friendly interface to store, share, and track changes to code, making it easier for developers to work together on software development.

Key features of GitHub:

  1. Code Repositories: GitHub stores code in "repositories" or "repos." Each repo is like a folder where developers keep their code and project files. πŸ—‚οΈ

  2. Collaboration: Multiple developers can work on the same project by "cloning" the repo to their computers, making changes, and "pushing" the changes back to GitHub. πŸ‘₯

  3. Version Control: GitHub uses a system called "Git," which tracks changes to the code. Developers can go back to previous versions if needed and see who made what changes. πŸ”€πŸ“œ

  4. Issues and Pull Requests: Developers can report issues or suggest changes in a project through "issues" and "pull requests." This fosters communication and problem-solving. πŸ“βœ‰οΈ

  5. Community and Learning: GitHub is not just a code-sharing platform; it's a community. Developers can learn from others' code, contribute to open-source projects, and collaborate on exciting projects. 🌐🀝

πŸ” What is Version Control? What types of version controls

Version control is a system that keeps track of changes in files over time so you can go back to specific versions later. It helps you undo changes, compare different versions, and see who made certain changes. πŸ”πŸ”„

There are two main types of version control systems:

  1. Centralized Version Control System (CVCS): It uses a central server to store all versions of a project's files. Developers check out files from the server, make changes, and check them back in. Examples are Subversion and Perforce. πŸ’πŸ’»

  2. Distributed Version Control System (DVCS): Developers clone the entire project repository, including its history, to their local computers. They work independently and can later merge their changes back into the main repository. Examples are Git, Mercurial, and Darcs. πŸŒπŸ”§

Both systems help teams collaborate, manage changes, and maintain project history effectively. They are valuable tools for developers working on projects with multiple contributors. πŸ€πŸš€

🌐 Why do we use distributed version control over centralized version control?

We use Distributed Version Control Systems (DVCS) over Centralized Version Control Systems (CVCS) for several reasons:

  1. Offline Work: With DVCS, developers can work offline and make changes to the code without needing a constant internet connection. They can commit changes locally and later synchronize with the central repository when online. πŸ“ΆπŸ’»

  2. Faster Performance: DVCS allows developers to perform version control tasks quicker since most operations are done locally without relying on a central server. This leads to a smoother and faster development process. βš‘πŸš€

  3. Enhanced Collaboration: Each developer in a DVCS has a complete copy of the project and its history. This promotes better collaboration as they can work independently and later merge their changes back into the main repository. πŸ€πŸ”„

  4. More Flexibility: DVCS allows developers to create multiple branches and work on different features or fixes simultaneously. They can share their changes with specific team members or work on experimental features without affecting the main codebase. πŸŒΏπŸ’‘

  5. Increased Security: The distributed nature of DVCS means that the project history is stored on multiple servers and computers. This redundancy makes it more resistant to data loss compared to CVCS, where the central server contains the entire history. πŸ”’πŸ”

  6. Decentralization: In DVCS, no single point of failure exists, and developers are not dependent on a central server. This decentralization provides more autonomy and reliability to the team. πŸŒπŸ›οΈ

Overall, Distributed Version Control offers greater flexibility, speed, collaboration, and security, making it a preferred choice for many development teams in modern software development workflows. 🌟πŸ‘₯πŸ›‘οΈ

πŸš€ Task 1: Install Git

To get started, we'll install Git on your computer. Git works on Windows, macOS, and Linux. Follow these simple steps:

  1. Go to git-scm.com/downloads, the official Git website.

  2. Download the installer that matches your operating system.

  3. Run the installer and follow the on-screen instructions to finish the installation.

  4. Once the installation is done, open a terminal or command prompt, and type git --version to make sure Git is installed correctly. You should see the version number displayed.

Great job! Git is now successfully installed on your computer. Let's move on to the next task. πŸš€πŸ’»

🀝 Task 2: Create a GitHub Account

GitHub is a popular platform where people store their Git projects and work together on them. If you don't have a GitHub account yet, here's how you can create one:

  1. Open your web browser and go to github.com.

  2. On the GitHub homepage, click on the "Sign up" button.

  3. Fill in the required information, like your username, email, and password.

  4. Choose a plan that suits you (Free or one of the paid options) based on your needs.

  5. Complete the verification process, which might include solving a CAPTCHA or confirming your email.

Once you finish these steps, congratulations! You've successfully made your GitHub account. Now, you can start sharing and collaborating on your projects. 🌟🀝

πŸ“ Exercise 1: Create a New Repository on GitHub

Let's get started by creating a new repository on GitHub, where we'll keep and organize our code. Follow these simple steps:

  1. Open your web browser and visit github.com.

  2. Log in to your GitHub account.

  3. On the GitHub homepage, click the "+" button at the top-right corner, then select "New repository" from the menu.

  4. Give your repository a meaningful name.

  5. You can also add a description to give more details about your repository.

  6. Choose whether you want the repository to be public or private, depending on your needs.

  7. Finally, click the "Create repository" button to create your new repository. That's it! Your central code storage is ready to go. πŸŽ‰

πŸ“‚ Exercise 2: Clone the Repository to Your Local Machine

Our repository is created on GitHub. You can now use the "git clone" command to duplicate the central repository onto your local machine's repository. Here's how you can do it in simple steps:

  1. Go to your repository page on GitHub and click on the "Code" button.

  2. Copy the repository URL.

  3. Open the terminal or command prompt on your computer.

  4. Navigate to the directory where you want to save the repository.

  5. Use the command "git clone" followed by the repository URL you copied. For example: git clone github.com/your-username/your-repository.git

  6. Press Enter, and the repository will be cloned to your local machine.

Great job! πŸ‘ You have successfully cloned the repository to your local machine. Let's proceed to the next exercise. πŸš€

πŸ”„ Exercise 3: Make Changes, Commit, and Push

Now that you have the repository copied to your computer, you can make changes to the files and keep track of those changes. Follow these simple steps:

  1. πŸšΆβ€β™‚οΈ Move to the repository directory.

  2. πŸ“„ Create two files using the touch command.

  3. πŸ” Use the command "git status" to see the changes you made. It will show the modified files.

  4. βž• Use the command "git add" followed by the file names to prepare the tracking changes. For example: "git add filename.txt" or "git add ." to track all changes. Now check the status and our file is now tracked.

  5. πŸ’Ό Use the command "git commit" to save the changes with a meaningful message describing the modifications. For example: git commit -m 'Added new files'

  6. πŸš€ Finally, use the command "git push" to upload the committed changes back to the repository on GitHub. For example: "git push origin main" or "git push origin master," depending on the branch name.

By following these steps, you'll successfully make changes to your GitHub repository, commit the changes, and push them back to the remote repository. This process ensures that your code is version-controlled and accessible to collaborators on GitHub. πŸš€

Did you find this article valuable?

Support Sahil Kamble's blog by becoming a sponsor. Any amount is appreciated!

Β