Today, we're going to explore the core of version control- Git and GitHub. If you've been with us so far, you've already started learning about these important tools. Now, we're going to dive deeper into Git and GitHub to boost your DevOps skills.
What is Git?
Git is a distributed version control system (DVCS) that empowers developers to manage and track changes to their codebase.
Now, you might wonder why Git is the go-to choice for version control among DevOps engineers. Here are some compelling reasons:
Efficiency: Git is renowned for its speed. Common version control operations like commits, branching, and merging are lightning-fast, thanks to its local repository setup.
Branching and Merging: Git excels in branching and merging, enabling clean development workflows. Feature branches, bug fixes, and code reviews are a breeze.
Collaboration: With Git, collaborating on projects is smooth, even across distributed teams. You can work on your local copy, push changes to a central repository, or directly pull from colleagues' repositories.
Security: Git enhances security through access control mechanisms and cryptographic keys. Your project's integrity is maintained even if a developer's machine is compromised.
What is the difference Between Main Branch and Master Branch?
The terms "main branch" and "master branch" are often used interchangeably in version control systems like Git.
However, there's a shift in terminology due to cultural sensitivity and inclusivity concerns:
Historically, "master" was commonly used to denote the default or primary branch in Git repositories.
In many projects and organizations, "master" was the branch where the main development and integration work took place.
"Main" is an alternative term that has gained traction to replace "master" in version control terminology.
It is often used to describe the primary or default branch, serving the same purpose as the "master" branch.
Difference between Git and GitHub:
|Distributed Version Control System (DVCS)||Web-based platform and service|
|Helps developers track changes in their code and collaborate with others.||Provides a platform for hosting, sharing, and collaborating on Git repositories.|
|Git is installed and run on your local machine.||GitHub hosts remote repositories on its servers.|
|Git operates offline.||GitHub operates online.|
|Git is open source.||GitHub is a cloud-based service that offers both free and paid plans.|
How do you create a new repository on GitHub?
Go to GitHub (https://github.com).
Log in to your GitHub account.
Click on the "+" icon in the top right corner and select "New repository."
Fill in the repository name, description, and other settings.
Choose the repository visibility (public or private).
Click "Create repository."
What is the difference between local & remote repositories?
A local repository is a copy of a Git repository that resides on your local machine. It contains all the project files, version history, and branches.
You interact with the local repository using Git commands on your computer. This allows you to make changes, create branches, commit changes, and manage your code offline.
A remote repository is a copy of a Git repository hosted on a remote server, such as GitHub. It serves as a central hub for collaboration and sharing code with others.
Remote repositories are used for team collaboration, backup, and sharing code with contributors. They enable multiple people to work on the same project, share their changes, and track progress.
When you push changes from your local repository to a remote repository, others can access your work and collaborate with you.
How to connect local to remote?
To connect your local repository to a remote repository, follow these steps:
Create a Remote Repository: First, create a remote repository on a platform like GitHub.
Link a local Repository to a Remote Repository:
Open your local repository in a terminal.
git remote addcommand to connect your local repository to the remote repository. You'll specify a name for the remote repository (commonly named "origin") and the URL of the remote repository.
git remote add origin
Push Your Code: To send your local code to the remote repository, use the
git pushcommand. You'll specify the remote repository's name (e.g., "origin") and the branch (here "main") you want to push.
git push origin main
Set your user name and email address, which will be associated with your commits.
Create a repository named "Devops" on GitHub.
Connect your local repository to the repository on GitHub.
cd /path/to/your/git/project git init
git remote add origin
Create a new file in Devops/Git/Day-02.txt & add some content to it.
git add .
git commit -m "<your_commit_message>"
Push your local commits to the repository on GitHub.