Introduction
Imagine you're building something really cool with a bunch of friends. But you all need to make sure you're working on the same page, right? That's where version control systems come in – they're like magic tools that help you and your friends organize your work and put it together.
Now, there are two super popular tools in this world: Git and GitHub. They're like the superheroes of getting things done. They're known for being good at making sure everyone works smoothly together, like a well-oiled machine. Here, we will cover the basics of Git and GitHub, providing a step-by-step guide for DevOps engineers to get started.
What is Version Control and its Types?
Version control is a system that helps developers track changes to their code over time. It provides a structured way to collaborate on projects, maintain a history of changes, and revert to previous versions when needed. In a DevOps context, version control is vital for managing infrastructure-as-code, application code, and configuration files in a controlled and organized manner.
Version control comes in two main types: centralized and distributed.
Centralized Version Control: In this model, a central server hosts the repository, and developers check out and commit changes directly to it.
Example: Let's say you and your friends are painting a landscape mural. One artist adds a beautiful sun to their section of the mural. They show it to everyone, and if everyone likes it, they commit the change to the central mural. Now everyone can see the bright sun in the landscape.
Centralized Version Control is like this art studio setup. The central server is where everyone shares their changes and sees the evolving project. It's a good way to work together, but if something happens to the central server like it goes offline, everyone's work might be affected.
Distributed Version Control: Distributed version control systems, like Git, distribute the repository to each developer's machine. This allows for a more flexible and decentralized workflow, as developers can work offline and commit changes locally before syncing them with the central repository.
What is Git?
Git is like a smart system for keeping track of changes in computer code (like the instructions that make software work) and other files. It's a bit like having a time machine for your work. Whenever you make a change, Git takes a snapshot of how things look at that moment. This means you can always go back to earlier versions if you need to. It's really helpful when many people are working on the same project. Git makes sure everyone's changes fit together neatly and avoids confusion. So, in short, Git is a tool that helps programmers work together, keep track of changes, and maintain a record of how things evolve over time.
What is GitHub?
GitHub is a web-based platform that provides a hosting service for Git repositories. It adds a graphical interface and a set of features for collaboration, making it easier for developers to work together on projects. GitHub offers features like issue tracking, pull requests, code reviews, and integration with various development tools.
Tasks :
Let's dive into some hands-on tasks with Git and GitHub.
1. Install Git on Your Computer
To install Git on your computer, follow these steps:
For Windows: Download the Git installer from the official website and run the executable.
For macOS: You can install Git using Homebrew by running
brew install git
in the terminal.For Linux: Use your distribution's package manager to install Git. For example, on Ubuntu, run
sudo apt-get install git
.You can download it from the official website at : https://git-scm.com/downloads
2. Create a Free Account on GitHub
Open your web browser and go to the GitHub website: https://github.com/
Click on the "Sign up" button
enter your information to create an account as Username, Email Address, Password
After entering the required information, click on the green "Create account" button.
Verify your email address
Once your email is verified, you'll have access to your new GitHub account
For detailed info check this: https://www.youtube.com/watch?v=c-NikCpec7U
3. Create a New Repository on GitHub and Clone It
Log in to your GitHub account.
Click on the "+" sign in the top right corner and select "New Repository."
Provide a name, description, and other settings for your repository.
Click "Create repository." now, the repository created.
To clone the repository to your local machine, copy the repository's URL from the GitHub page and run
git clone <repository_url>
in your terminal.
4. Make some changes to a file in the repository and commit them to the repository using Git
Create and edit a file in the repository & check the git status, it is showing file is untracked in red colour.
Use
git add <file>
to stage the changes for commit.Commit the changes using
git commit -m "Your commit message here"
.check the updates with git log.
5. Push the changes back to the repository on GitHub
After committing your changes locally, use
git push
to send the changes to the GitHub repository.Conclusion
In the world of DevOps, mastering version control systems like Git and platforms like GitHub is essential. This blog post covered the basics of Git and GitHub, from understanding version control to performing hands-on tasks such as installation, repository creation, cloning, committing changes, and pushing those changes back to the repository. As you continue your DevOps journey, these skills will prove invaluable in managing code, collaborating effectively, and maintaining a streamlined development process. So go ahead, explore further, and leverage the power of Git and GitHub in your DevOps endeavors.