Day-09 Task: Deep Dive in Git & GitHub for DevOps Engineers
What is Git and why is it important?
Git is a version control system that helps you manage and track changes in your code.
It's important because it allows collaboration, keeps a history of changes, and helps prevent chaos in coding projects.
What is the difference Between the Main Branch and the Master Branch?
The main difference is mostly in terminology. Historically, "master" was commonly used as the default branch name in Git. However, due to concerns about the term's association with slavery, many projects and platforms now use "main" instead of "master" as the default branch name to promote inclusive language. In terms of functionality, they serve the same purpose as the default branch where the latest changes are typically found.
Can you explain the difference between Git and GitHub?
Feature | Git | GitHub |
Definition | A distributed version control system. | A web-based platform for hosting Git projects. |
Functionality | Manages and tracks code changes. | Provides a platform for collaboration, code hosting, and project management. |
Installation | Needs to be installed locally on a computer. | Accessed through a web browser; no installation is required for basic usage. |
Usage | Used for version control on local machines. | Used for collaboration, remote repositories, issue tracking, and more. |
Repositories | Can be local or remote. | Hosts remote repositories accessible over the web. |
Collaboration | Supports collaboration but requires coordination. | Facilitates easier collaboration with features like pull requests, issues, and project management tools. |
Examples | Git commands (git init, git commit, etc.). | GitHub features (pull requests, issues, forks, etc.). |
Git is the version control system itself, while GitHub is a platform that uses Git for collaboration and project management, making it more user-friendly and accessible.
How do you create a new repository on GitHub?
Creating a new repository on GitHub is a straightforward process. Here's a basic step-by-step guide:
Sign in to GitHub:
- If you don't have an account, you need to sign up for one.
Go to your GitHub dashboard:
- Once logged in, click on the "+" icon in the top right corner of the page.
Choose "New repository":
- In the dropdown, select "New repository."
Fill in the repository details:
Enter a name for your repository.
Choose between public and private visibility (public repositories are visible to everyone, while private ones require a subscription).
Initialize with a README if you want to create a repository with an initial README file.
Create the repository:
- Click the "Create repository" button.
What is the difference between local & remote repositories? How to connect local to remote?
Feature | Local Repository | Remote Repository |
Location | On your local machine. | Hosted on a remote server (e.g., GitHub). |
Purpose | The working directory for code changes. | Shared space for collaboration and storage. |
Access | Only accessible on your machine. | Accessible to multiple users over the internet. |
Control | Direct control and autonomy. | Shared control, often by a team of contributors. |
Usage | Individual development and testing. | Collaboration, code sharing, and version control. |
Commands | Common Git commands (e.g., git commit). | Git commands for collaboration (e.g., git push). |
Example Platforms | A local machine with Git installed. | GitHub, GitLab, Bitbucket, etc. |
Connecting a local repository to a remote one involves a few steps. Here's a simple guide:
Create a Remote Repository:
Create a repository on a platform like GitHub.
Navigate to Your Local Repository and Initialize Git
#git init
Add a Remote Link:
Use the following command to add a remote link to your local repository. Replace
<remote_repository_url>
with the actual URL of your remote repository.#git remote add origin <remote_repository_url>
Verify the Connection:
To verify that the remote repository is correctly linked, you can use:
#git remote -v
This should display the fetch and push URLs for the remote repository.
Push Your Changes to the Remote Repository:
If you have existing code in your local repository, you can push it to the remote repository using:
#git push -u origin master
Replace "master" with your branch name if it's different.
Now, your local repository is connected to the remote one.
Task-1:
Set your user name and email address, which will be associated with your commits.
#git config --global user.name "IrfanMomin"
#git config --global user.email "IrfanTechOpsgamil.com"
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
-
Subscribe to my newsletter
Read articles from Irfan S Momin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Irfan S Momin
Irfan S Momin
A Foodie Software Engineer's Journey to Eating Healthy and Learning Something New Every Day