Day 8: Basic Git & GitHub for DevOps Engineers


What is Git?
Git is a distributed version control system (VCS) that is widely used for tracking changes in source code during software development. Git is known for its speed, flexibility, and the ability to handle both small and large projects efficiently.
What is GitHub?
GitHub is a web-based platform that provides hosting for software development and version control using the Git system. It offers a range of features to facilitate collaboration among developers and teams working on software projects. GitHub is one of the most popular and widely used platforms for hosting and managing code repositories.
What is Version Control? How many types of version controls we have?
Version control is a system that manages changes to a set of files over time. It allows multiple people to collaborate on a project, track changes, and maintain a history of modifications made to the files. Version control is crucial for software development and other fields where files are edited and updated collaboratively.
There are two main types of version control systems: centralized version control systems (CVCS) and distributed version control systems (DVCS).
A centralized version control system (CVCS) uses a central server to store all the versions of a project's files. Developers "check out" files from the central server, make changes, and then "check-in" the updated files. Examples of CVCS include Subversion and Perforce.
A distributed version control system (DVCS) allows developers to "clone" an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.
Why we use distributed version control over centralized version control?
Distributed version control systems (DVCS) offer several advantages over centralized version control systems (CVCS), which contribute to their popularity and widespread adoption in modern software development. Here are some of the key reasons why distributed version control is often preferred:
Offline Work: In a DVCS, each developer has a complete copy of the entire repository, including its history. This means that developers can work offline, committing changes and branching without needing constant access to a central server.
Speed and Performance: DVCS systems like Git are designed to be incredibly fast, especially for common operations like committing changes, creating branches, and merging code.
Easy Branching and Merging: DVCS systems make branching and merging operations much smoother. Developers can create branches to work on new features or bug fixes independently, and then merge those changes back into the main codebase when they're ready. This allows for parallel development without disrupting the main codebase.
Support for Open Source and Forking: DVCS systems are particularly well-suited for open-source projects. Anyone can clone a public repository, make changes, and submit pull requests.
Task 1: Installation of Git
Download the Git installer for Windows from the official Git website: https://git-scm.com/download/win
Run the installer and follow the on-screen instructions. You can generally use the default settings unless you have specific preferences.
After installation, you can verify that Git is properly installed by opening a terminal or command prompt and running:
git --version
Task 2: Create a free account on GitHub
Visit github.com and click "Sign Up."
Choose the "Free" plan and create an account with email or Google.
Verify your email to activate your account.
Complete your profile settings and personalize your GitHub experience.
Excercise 1: Create a new repository on GitHub.
Excercise 2: Clone the Repository to Your Local Machine
In the terminal, use the
git clone
command followed by the repository URL you copied earlier. For example:git clone https://github.com/your-username/your-repository.git
Excercise 3: Make some changes to a file in the repository and commit them to the repository using Git
Open a File:
- Use a text editor or code editor to open a file from your cloned repository that you want to modify. You can use any editor you're comfortable with, such as Notepad (Windows), Visual Studio Code, Sublime Text, etc.
Make Changes:
- Edit the content of the file to make the desired changes. For example, add some text or modify existing lines.
Save the File:
- Save the changes you've made to the file.
Check Status:
Open your terminal or command prompt.
Navigate to the repository's directory using the
cd
command.Run the following command to see the status of your repository:
git status
This will show you which files have been modified.
Stage Changes:
Use the
git add
command to stage the changes you made. Replacefilename
with the actual name of the file you edited.git add filename
If you want to stage all changes in the repository, you can use:
git add .
Commit Changes:
Now, commit the staged changes using the
git commit
command. This command also opens a text editor for you to enter a commit message.git commit
Alternatively, you can use the
-m
flag to provide a commit message directly in the command:git commit -m "Add a description of your changes"
Push Changes:
If you cloned a remote repository, you can use the
git push
command to push your committed changes back to the remote repository.git push origin master
Subscribe to my newsletter
Read articles from Moiz Asif directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
