Deep Dive in Git & GitHub for DevOps Engineers.
#90daysdevops
#day09
What is Git and why is it important?
Git is a version control system that helps developers track changes to their code over time, collaborate with others, and manage multiple project versions. It's important because it provides a structured approach to software development, making it easier to manage and collaborate on code.
Importance of git
Track Changes – Changes can be tracked as someone making a change leaves a commit message about it.
Backup and Restore – It helps to maintain the source code backup.
Collaboration - It enables the software teams to collaborate.
Branching and Merging – Changes are made on a branch and after being approved, they can be merged with the master branch. You can see who changed the file and what parts of the content are changed.
Deployment - It deploys the source code on the server with only one command.
Main Branch Vs Master Branch
In practical terms, the difference between the "main" and "master" branches is largely a matter of convention and preference. Some developers and organizations prefer to use "main" to refer to the default branch, while others continue to use "master".
Regardless of which term is used, the default branch is typically where the latest stable version of the codebase is stored, and other branches are created off of it for experimental features or bug fixes
Git vs GitHub
Git is a distributed version control system that allows developers to track changes to source code and collaborate on a project. It provides a way to manage code changes over time, allowing developers to easily review and merge changes made by different contributors. Git is often used locally on a developer’s computer or on a company’s own servers to manage the codebase.
GitHub, on the other hand, is a web-based platform that provides a graphical interface for Git. It is a cloud-based service that hosts Git repositories and provides additional collaboration features, such as issue tracking, pull requests, and code reviews. It allows developers to store and share their code with others, making it easier to collaborate on a project with a distributed team.
How do you create a new repository on GitHub?
To create a new repository on GitHub, follow these steps:
Log in to your GitHub account.
Click on the "+" icon in the top right corner of the page.
Select "New repository" from the dropdown menu.
Enter a name for your repository.
Add a description if you like (optional).
Choose whether you want the repository to be public or private.
Select the checkbox to "Initialize this repository with a README" (optional).
Choose a license if you like (optional).
Click "Create repository".
What is the difference between local & remote repositories?
A local repository is a copy of a Git repository that is stored on your own computer, while a remote repository is a copy that is stored on a remote server or hosting service, such as GitHub.
To connect a local repository to a remote repository
Copy the remote repository’s URL.
In the terminal or command prompt, enter the following command to add the remote repository URL to your local Git repository:
git remote add origin <remote-repository-URL>
- Verify that the remote repository has been added to your local Git repository by running the following command:
git remote -v
This command will show you a list of all the remote repositories that your local repository is connected to.
To set user name and email address, which will be associated with your commits :
git config --global user.name "your name"
git config --global user.email "your email"
Push your local commits to the repository on GitHub
add your file to the staging area using
git add <file_name>
then commit the changes using
git commit -m "any message"
finally, push your file to GitHub using the command
git push origin main
, here main is the name of the branch you want to push.
Thank you for reading!!
Great initiative by the #trainwithshubham community.