Day 9 Task: Deep Dive in Git & GitHub for DevOps Engineers.
Advanced git and github
Table of contents
What is Git and why is it important?
Git is distributed version control system, developed by 'linus torvald' in 2005,
Used to manage source code.
Here are some reasons why Git is important:
Collaboration: Git allows multiple developers to work on the same codebase simultaneously and collaborate on changes. This helps to speed up development and improves overall efficiency.
Version Control: Git enables version control, which means that developers can keep track of changes made to the codebase over time. This makes it easy to revert to an earlier version if something goes wrong or to compare different versions of the code.
Branching and Merging: Git allows developers to create different branches of the codebase and work on different features or fixes simultaneously. This makes it easy to isolate changes and test them independently before merging them back into the main codebase.
Backup and Recovery: Git repositories serve as a backup of the codebase and can be used to recover lost or deleted files. This is particularly important for critical projects where losing code could result in significant downtime or financial losses.
Open Source: Git is an open-source project, which means that it is free to use and can be modified by anyone.
What is the difference Between Main Branch and Master Branch??
In general, the main branch and the master branch are the central branches in a Git repository, and they are used to track the current state of the project's source code. The main branch is the branch to that developers are expected to commit their changes to, and it is the branch that is used to create releases of the project. The master branch is a special branch that is used to track the main branch and ensure that the project's source code is always in a stable and deployable state
Difference between Git and GitHub?
GIT
GITHUB
Git is a software.
GitHub is a service.
Git is a command-line tool
GitHub is a graphical user interface
Git is installed locally on the system
GitHub is hosted on the web
Git is maintained by Linux.
GitHub is maintained by Microsoft.
Git is focused on version control and code sharing.
GitHub is focused on centralized source code hosting.
Git is a version control system to manage source code history.
GitHub is a hosting service for Git repositories.
Git was first released in 2005.
GitHub was launched in 2008.
Git is open-source licensed.
GitHub includes a free tier and a pay-for-use tier.
Git has minimal external tool configuration.
GitHub has an active marketplace for tool integration.
Git provides a Desktop interface named Git Gui.
GitHub provides a Desktop interface named GitHub Desktop.
How do you create a new repository on GitHub?
First, log in to your GitHub account.
On the GitHub home page, click the "+" sign in the top right corner of the screen and select "New repository" from the drop-down menu.
On the "Create a new repository" page, enter a name for your repository in the "Repository name" field.
Optionally, you can add a description for your repository in the "Description" field.
Choose whether you want your repository to be public or private. Public repositories are visible to everyone, while private repositories are only visible to you and those you grant access to.
If you want to initialize your repository with a README, license, or .gitignore file, select the corresponding options.
Choose a license for your repository if you want to include one. If you don't want to include a license, select "None".
Click the "Create repository" button to create your new repository.
Your new repository is now created and you can start adding files and making changes to it. You can also clone the repository to your local machine using the Git command line or a Git client like GitHub Desktop.
What is the difference between local & remote repositories? How to connect local to remote?
A local repository is a copy of a Git repository that is stored on your local computer, while a remote repository is a copy of the same repository that is hosted on a remote server, such as GitHub
To connect a local repository to a remote repository, you can follow these steps:
Create a new repository on your remote server e.g. GitHub.
In your local repository, open a terminal or command prompt and navigate to the root of your project.
Run the following command to add the remote repository URL to your local repository:
git remote add origin <remote repository URL>
Replace
<remote repository URL>
with the URL of your remote repository.Push your local repository to the remote repository by running the following command:
git push -u origin master
Tasks
task-1:
Set your user name and email address, which will be associated with your commits.
To set a user name.
sudo git config --global
user.name
"Your Name"
To set email id.
sudo git config --global
user.email
"
your.email@example.com
"
verify user name and email.
sudo git config --list
task-2
Create a repository named "Devops" on GitHub
Connect your local repository to the repository on GitHub.
sudo git remote add origin <central git repo>
To verify that a remote named "origin" has been added to your Git repository, you can use the following command:
git remote -v
Create a new file in Devops/Git/Day-02.txt & add some content to it
Push your local commits to the repository on GitHub