๐๐ Day 9 DevOps Challenge - ๐ Mastering Git & GitHub for DevOps Excellence
Table of contents
- 1. What is Git and why is it important?
- 2. What is the difference between Main Branch and Master Branch?
- 3. Can you explain the difference between Git and GitHub?
- 4. How do you create a new repository on GitHub?
- 5. What is the difference between a local & remote repository? How to connect local to remote?
- Task 1: Set your user name and email address
- Task 2: Create a repository on GitHub
- Task 3: Connect your local repository to GitHub
- Task 4: Create a new file and add content
- Task 5: Push your local commits to GitHub
1. What is Git and why is it important?
Git is like a digital time machine for your code ๐ฐ๏ธ. It helps programmers work on projects together, keeping track of changes they make ๐. Git is important because it lets you collaborate without messing up each other's work, and you can always go back to older versions if something goes wrong ๐.
2. What is the difference between Main Branch and Master Branch?
Think of them like different names for the same thing ๐. "Master" used to be a common name, but now many use "Main" to be more respectful. Both are default branches in Git where your latest code lives ๐ฑ.
3. Can you explain the difference between Git and GitHub?
Git is the tool that helps manage versions of your code, while GitHub is like a website where you can store and share your code with others ๐ช. Think of Git as the toolbox and GitHub as the workshop where you show your projects.
4. How do you create a new repository on GitHub?
It's like making a new online folder for your code ๐. You go to GitHub, click on "New," give your repository a name and description, decide if it's public or private ๐, and then create it. Now you have a place to store your code online!
5. What is the difference between a local & remote repository? How to connect local to remote?
A local repository is on your own computer ๐ฅ๏ธ, while a remote repository is stored on a server (like GitHub) ๐. Connecting them is like setting up a bridge. First, you copy the remote repository's URL. Then, in your local repository, you run a command to add that URL as a "remote." After that, you can send your code from local to remote using commands like "git push" ๐ค. It's like sharing your local project with others on the web!
Task 1: Set your user name and email address
Open your terminal or command prompt and enter these commands, replacing "Your Name"
and "
your@email.com
"
with your actual name and email address:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
To check the configured user name and email address
git config user.name
git config user.email
Task 2: Create a repository on GitHub
Log in to your GitHub account.
Click the "+" icon in the top right corner and select "New repository."
Name your repository "Devops" and add a description if you'd like.
Choose the repository visibility (public or private).
You can choose to initialize the repository with a README file, but for now, let's skip that.
Click "Create repository."
Task 3: Connect your local repository to GitHub
Open your terminal and navigate to the directory where you want to create your local repository.
Run these commands:
git init # Initialize a new Git repository
git remote add origin https://github.com/YourUsername/Devops.git
Replace "YourUsername"
with your actual GitHub username.
Task 4: Create a new file and add content
In your terminal, navigate to your local repository's directory.
Create the necessary folders and the file:
mkdir -p Devops/Git # Create the required folders
touch Devops/Git/Day-02.txt # Create the Day-02.txt file
- Open the
Day-02.txt
file in a text editor and add some content.
Task 5: Push your local commits to GitHub
In your terminal, navigate to your local repository's directory.
Run these commands:
git add . # Stage all changes for commit
git commit -m "Added Day-02.txt and content" # Commit your changes
git push -u origin master # Push your changes to the GitHub repository
If you encounter issues, ensure you've followed each step correctly and that your GitHub credentials are properly configured on your local machine.
After pushing changes to GitHub-repo
In a nutshell, pushing changes to a GitHub repository is like sharing your new toy with friends. ๐ฎ You're putting your latest work where everyone can see and play with it. Just press a button, and your updates go from your computer to a special place on the internet. It's teamwork made easy, like showing off your cool creations and making sure everyone's on the same page. ๐ค So, push away and let the fun collaboration begin! ๐