Welcome back to the #90DaysOfDevOps Challenge! Today, we're diving deep into the world of Git and GitHub, exploring their significance for DevOps Engineers. Let's unravel some key concepts and tackle hands-on tasks to solidify our understanding.
Understanding Git:
What is Git and Why is it Important?
Git is a distributed version control system that revolutionizes collaboration in software development. Its importance lies in:
Version Control: Tracking changes, facilitating rollbacks, and maintaining a project's history.
Collaboration: Enabling multiple contributors to work seamlessly on a project.
Branching: Supporting parallel development through branches.
History Tracking: Providing a comprehensive log of project modifications.
You might be wondering what's the difference between Git and GitHub.
Git:
What it is: Git is a distributed version control system designed to track changes in source code during software development.
Key Features:
Version Control: Manages and tracks changes in the source code.
Branching: Supports the creation of branches for parallel development.
Collaboration: Enables multiple developers to work on a project simultaneously.
Local Operation: Operates on a developer's local machine.
Why it's Important:
History Tracking: Keeps a comprehensive history of changes made to the code.
Collaboration: Facilitates teamwork and concurrent development.
Rollback: Allows reverting to previous versions of the code.
GitHub:
What it is: GitHub is a web-based platform that provides hosting for Git repositories, adding collaboration features on top of Git.
Key Features:
Remote Hosting: Serves as a central hub for hosting Git repositories.
Collaboration Tools: Offers tools for issue tracking, pull requests, and project management.
Visibility: Enhances visibility and accessibility of projects.
Web-based Interface: Provides a user-friendly interface for working with Git.
Why it's Important:
Collaboration: Facilitates remote collaboration among developers.
Project Management: Includes tools for tracking issues, managing projects, and conducting code reviews.
Community Engagement: Enables developers to showcase their work, contribute to open-source projects, and collaborate on a global scale.
Key Difference:
Git is a Version Control System that manages and tracks changes locally on a developer's machine.
GitHub is a Platform that hosts Git repositories and adds collaboration features like issue tracking, pull requests, and project management.
In summary, while Git is the underlying version control system, GitHub is a platform built around Git, enhancing its capabilities for collaboration, visibility, and project management. They work hand-in-hand to streamline the development workflow, from local coding to global collaboration.
Now that we've explored what Git is and its importance as well as it's differences to github, let's delve into the difference between the main branch and the master branch.
Main Branch vs. Master Branch
In Git, the distinction between "main" and "master" is a matter of terminology. Traditionally, "master" was the default branch name, but to promote inclusivity and sensitivity, many communities now prefer using "main." Both refer to the primary branch in your repository.
Now, let's understand how to create a repository on GitHub.
Here's a step-by-step guide:
Log in to Your GitHub Account:
Open your web browser and navigate to GitHub.
Log in with your GitHub credentials.
Navigate to Your Dashboard:
- Once logged in, click on the '+' sign in the top right corner of the GitHub interface.
Choose "New repository":
- Select "New repository" from the dropdown menu.
Fill in Repository Details:
Provide a name for your repository. This can be anything meaningful related to your project.
Add an optional description to briefly explain the purpose of your repository.
Choose between public or private visibility based on your needs.
Initialize this repository with a README if you want to add a README file right from the start.
You can also add a .gitignore file and choose a license.
Create Repository:
- Click the "Create repository" button.
Congratulations! You have successfully created a new repository on GitHub.
Now, Let's Have a look at the difference between local and remote repo.
Difference Between Local & Remote Repository:
Local Repository:
Location: Exists on your local machine (computer).
Purpose: Holds your project's files and the complete history of changes made to those files.
Access: Accessed and managed directly on your computer.
Operations: Git commands like commit, branch, and merge are performed locally.
Remote Repository (e.g., GitHub):
Location: Hosted on a server (remote location), often on platforms like GitHub.
Purpose: Serves as a centralized hub for collaboration and backup.
Access: Accessed over the internet.
Operations: Git commands like push and pull are used to synchronize changes between the local and remote repositories.
Connecting Local to Remote Repository:
Initialize a Local Repository:
Open your terminal.
Navigate to the project directory.
Use
git init
to initialize a local repository.
Link Local Repository to Remote:
On GitHub, create a new repository.
Copy the repository URL.
git remote add origin <repository-url>
Push Local Changes to Remote:
- After making changes locally, stage and commit them.
git add .
git commit -m "Your commit message"
- Push changes to the remote repository.
git push -u origin main
(Replace main
with your branch name if different)
Now, your local and remote repositories are connected. You can pull changes from the remote or push your local changes to keep them in sync.
Now onto our tasks
Tasks:
task-1:
- Set your user name and email address, which will be associated with your commits.
Setting your user name and email address in Git is crucial to associate your commits with your identity. Here's how you can accomplish Task-1:
Open your terminal or command prompt.
Use the following commands to set your user name and email address:
git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
Replace "Your Name" with your actual name and "your.email@example.com" with the email address associated with your GitHub account.
Verify that your settings have been updated:
git config --global user.name git config --global user.email
These commands should display the name and email you just set.
Now, your Git configuration is updated with your user name and email address, and any commits you make will be associated with this information. This is an important step for tracking contributions and collaborating with others.
task-2:
Create a repository named "Devops" on GitHub
Connect your local repository to the repository on GitHub.
Create a new file in Devops/Git/Day-02.txt & add some content to it
Push your local commits to the repository on GitHub
Let's go through Task-2 step by step:
Step 1: Create a Repository Named "Devops" on GitHub
Log in to your GitHub account.
Click on the "+" sign in the top right corner and select "New repository."
Name your repository "Devops."
Optionally, add a description, choose public or private visibility, and initialize with a README.
Click "Create repository."
Step 2: Connect Your Local Repository to GitHub
Assuming you've already initialized a local Git repository:
In your terminal, navigate to your local repository:
cd path/to/your/local/repo
Link your local repository to the remote GitHub repository:
git remote add origin <repository-url>
Replace
<repository-url>
with the URL of the repository you just created on GitHub.
Step 3: Create a New File in Devops/Git/Day-02.txt & Add Content
Navigate to the "Devops/Git" directory in your local repository:
cd path/to/your/local/repo/Devops/Git
Create the "Day-02.txt" file:
touch Day-02.txt
Open the file in your preferred text editor, add some content, and save the changes.
Step 4: Push Your Local Commits to GitHub
Stage and commit your changes:
git add . git commit -m "Add Day-02.txt with content"
Push your local commits to the GitHub repository:
git push -u origin main
(Replace
main
with your branch name if different)
Now, your local changes are pushed to the "Devops" repository on GitHub.
That's all for today. Stay cool, stay humble, and keep coding happily! See you in the next blog!