What is Git and why is it important? |
What is Git and why is it important? |
Explain the difference between Git and GitHub? |
How do you create a new repository on GitHub? |
What is difference between local & remote repository? How to connect local to remote? |
Task-1: Set your user name and email address, which will be associated with your commits. |
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 |
Introduction
Welcome to Day 9 of our DevOps journey! π Today, we'll be taking a deep dive into the world of Git and GitHub. Strap in, because by the end of this blog, you'll not only understand the basics but also have completed some hands-on tasks to reinforce your knowledge.
What is Git? π€
Git is a distributed version control system that tracks changes in source code during software development. It enables multiple developers to collaborate seamlessly, maintaining a chronological record of modifications.
Let's understand it by using real world example
π Code Time-Traveler: Git is your code's time-travel machine. It remembers every change so you can go back and fix things. β°
π€ Teamwork Buddy: Think of Git as a dance floor for your code. Lots of people can dance (code) together without tripping over each other. ππΊ
π Coding Safety Net: Oops, made a mistake? Git's your superhero cape. Undo, and all's well again! π¦ΈββοΈ
Why is Git Important? π
π€ Seamless Collaboration: Git ensures a smooth dance of multiple developers on the same project, avoiding conflicts and promoting teamwork.
πΊοΈ Historical Tracking: It's the code historian, keeping a detailed record of changes, ensuring accountability, and swiftly resolving issues.
πΏ Branching for Innovation: Developers can play in their own sandbox, experimenting with new ideas in separate branches, all while keeping the main project stable.
π Global Contribution: Git's distributed nature fosters a global coding party, bringing diverse minds together, much like the collaborative spirit in projects such as Linux.
β¨ Error Reversal Capability: Acting as a safety net, Git allows quick and efficient undoing of changes, providing a fearless space for experimentation and growth. ππ©βπ»π¨βπ»
Some Other Points on it
Project Organizer: Keeps your code party organized, so it's not a wild mess. π
Idea Playground: Lets you try new things without messing up your main masterpiece. π¨
Code Harmony Conductor: Like the orchestra leader, making sure everyone plays together without chaos. π»πΊ
Main Branch vs. Master Branch Puzzle π§©
Ever wondered about the difference between the "Main" and "Master" branches in Git? Let's demystify it in a simple and playful way! π
Main Branch π
Name Evolution: "Main" is the contemporary and more inclusive term replacing "Master."
Primary Default Branch: Often set as the default branch when you create a new repository.
Symbol of Unity: Reflects the industry's move towards language that is considerate and mindful.
Master Branch π
Traditional Term: Historically used as the default branch name.
Rooted in Tradition: The term "Master" doesn't carry the same inclusive connotations as "Main."
Difference between Git and GitHub
π€ Git: Think of Git as the wizard behind the scenes, managing your code's history and changes. It's the engine that powers version control, enabling time travel and collaboration.
π GitHub: GitHub is like the cool clubhouse in the cloud where your Git repositories live. It provides a slick, user-friendly interface for collaboration, issue tracking, and team coordination. GitHub is the party venue for your code. ππ»
Creating a GitHub Repository π
π Log In to GitHub:
π€ Access Your Profile:
- Click on your profile picture in the top right corner to access the dropdown menu.
π Go to "Your Repositories":
- Select "Your repositories" from the dropdown menu.
β Click "New":
ποΈ Fill in Details:
- Name your repository Devops creative! Add a brief description, so others know what your project is all about.
π Choose Visibility:
π Initialize with a README:
- Opt to start your repository with a README file for an instant project overview.
π Click "Create Repository":
- Finally, hit the green "Create repository" button β your project's grand opening!
Local and Remote Repositories
The mystery of local and remote repositories β the dynamic duo powering collaboration and code magic. π§ββοΈβ¨
Local Repository: π
Your Personal Coding Space: Think of your local repository as your cozy home. It's where you do all the coding, experiment with new features, and make changes to your project.
No Internet Required: This is your offline haven, unaffected by the cyber waves. Your local changes are safe and sound within the walls of your coding sanctuary.
Remote Repository: π
The Cloud Kingdom: Now, imagine the remote repository as a magical cloud kingdom. It's the online version of your project, living on platforms like GitHub, GitLab, or Bitbucket.
Global Accessibility: The remote repository is accessible from anywhere with an internet connection. It's where teams collaborate, share ideas, and collectively contribute to the project.
Set your user name and email address, which will be associated with your commits.
Setting up your user name and email address associated with your commits is a crucial step in Git configuration. Follow these simple commands in your terminal:
Set Your User Name:
git config --global user.name "asifshaikh49"
Replace "Your Name" with your actual name. This helps Git identify who is making the changes.
Set Your Email Address:
git config --global user.email "asifshaikh@gmail.com"
Substitute "asifshaikh@gmail.com" with the email you use for your Git-related activities. This associates your commits with your email address.
Now, with your user name and email configured, Git will recognize your identity when you make commits.
Task 2 :
Create a Repository on GitHub
Visit GitHub.
Log in to your account.
Click on the "+" sign in the top right corner and select "New Repository."
Name it "Devops."
Optionally, add a description.
Click "Create repository."
Connect Local Repository to GitHub
In your local terminal:
Navigate to your project directory.
cd project
Initialize Git if you haven't already.
git init
Add the GitHub repository as a remote.
git remote add origin https://github.com/asifshaikh49/Devops.git
Create a New File and Add Content
Create the necessary directories and the file.
mkdir -p Devops/Git touch Devops/Git/Day-09.txt ls
Open the file and add some content.
echo "Hello, Day 2! DevOps is awesome!" >> Devops/Git/Day-02.txt vi Day-09.txt echo "Hello, Day 9! DevOps is awesome! another methode"
Push Local Commits to GitHub
Add the changes.
git add .
Commit the changes.
git commit -m "Adding Day-09.txt"
Check the status of git:
git Status
Add URL
git remote add origin https://github.com/asifshaikh49/Devops.git
- Generate a token :
Click on top right corner of your GitHub profile
Click on the setting
Click on Developer Setting
Select the Personal token
Select Classic token
Copy The link
Push to the GitHub repository.
git remote set-url origin --push https://{TOKEN}@github.com/asifshaikh49/Devops.git
git push -u origin main
Your local changes are now on GitHub. Head to your repository, and you'll find the magic in action