Table of contents
- π Introduction π
- πΎ What is Git?
- π€ What is GitHub?
- π What is Version Control? What types of version controls
- π Why do we use distributed version control over centralized version control?
- π Task 1: Install Git
- π€ Task 2: Create a GitHub Account
- π Exercise 1: Create a New Repository on GitHub
- π Exercise 2: Clone the Repository to Your Local Machine
- π Exercise 3: Make Changes, Commit, and Push
π 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:
Overwriting Changes: Concurrent edits to the same file may overwrite work, causing conflicts and data loss. π¬π
Tracking Changes: It's tough to monitor who altered what and when hampering progress and bug tracking. ππ
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:
Code Repositories: GitHub stores code in "repositories" or "repos." Each repo is like a folder where developers keep their code and project files. ποΈ
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. π₯
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. ππ
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. πβοΈ
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:
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. π’π»
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:
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. πΆπ»
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. β‘π
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. π€π
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. πΏπ‘
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. ππ
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:
Go to git-scm.com/downloads, the official Git website.
Download the installer that matches your operating system.
Run the installer and follow the on-screen instructions to finish the installation.
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:
Open your web browser and go to github.com.
On the GitHub homepage, click on the "Sign up" button.
Fill in the required information, like your username, email, and password.
Choose a plan that suits you (Free or one of the paid options) based on your needs.
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:
Open your web browser and visit github.com.
Log in to your GitHub account.
On the GitHub homepage, click the "+" button at the top-right corner, then select "New repository" from the menu.
Give your repository a meaningful name.
You can also add a description to give more details about your repository.
Choose whether you want the repository to be public or private, depending on your needs.
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:
Go to your repository page on GitHub and click on the "Code" button.
Copy the repository URL.
Open the terminal or command prompt on your computer.
Navigate to the directory where you want to save the repository.
Use the command "git clone" followed by the repository URL you copied. For example: git clone github.com/your-username/your-repository.git
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:
πΆββοΈ Move to the repository directory.
π Create two files using the touch command.
π Use the command "git status" to see the changes you made. It will show the modified files.
β 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.
πΌ Use the command "git commit" to save the changes with a meaningful message describing the modifications. For example: git commit -m 'Added new files'
π 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. π