What is Git and why is it important?
Git is a distributed version control system that is widely used in software development and other collaborative projects. It was created by Linus Torvalds in 2005 to manage the development of the Linux kernel, but its popularity has grown significantly, making it the de facto standard for version control in the software development industry.
In simple terms, version control systems like Git allow developers to track changes in their code over time and collaborate with others more effectively
Why Git is important?
History and Versioning: Git keeps a complete history of changes made to a project, storing each version of the codebase as "commits." This allows developers to go back in time and see how the code has evolved, making it easy to identify what changes were made, who made them, and when they were made.
Collaboration and Teamwork: Git enables multiple developers to work on the same project simultaneously without interfering with each other's work. Developers can create their own branches to work on specific features or fixes and later merge them back into the main codebase. This promotes collaboration and makes it easier to manage complex projects with distributed teams.
Branching and Merging: Branching is one of Git's most powerful features. It allows developers to create separate branches for different tasks, such as bug fixes or new features, without affecting the main codebase. Once the work is complete, branches can be merged back into the main branch, combining all the changes seamlessly.
Undo and Recovery: If a mistake is made or a bug is introduced, Git allows developers to revert to a previous commit or apply fixes quickly. This provides a safety net and reduces the risk of losing important work.
Code Review and Quality Control: Git integrates with code hosting platforms like GitHub and GitLab, facilitating code reviews and discussions among developers. Code reviews are essential for maintaining code quality, ensuring best practices are followed, and catching potential issues before they reach the main codebase.
Open Source Community: Git has become the backbone of the open-source community. It allows developers from all over the world to contribute to projects, making it easier for communities to collaborate on projects regardless of geographical barriers.
Scalability: Git is scalable, making it suitable for projects of any size, from small personal projects to large enterprise-level applications.
Offline Work: Git operates locally, which means developers can work on their code even when not connected to a network. This feature is particularly useful when working on the go or in environments with limited internet access.
Git is crucial for modern software development because it provides an efficient and reliable way to manage code, collaborate with others, and maintain the integrity and quality of projects. Its popularity and widespread adoption make it an essential tool for any software developer or team.
Difference between Git and GitHub?
Difference between local & remote repositories
Local Repository: A local repository is a copy of the version control repository that resides on your local computer. When you clone or initialize a repository on your computer, you create a local copy that contains the entire version history of the project. The local repository allows you to work on the code, make changes, create new branches, and commit your changes without needing a constant internet connection.
Remote Repository: A remote repository is a version control repository that exists on a remote server or hosting service (e.g., GitHub, GitLab, Bitbucket). It acts as a centralized location where all developers working on a project can push their changes and pull changes made by others. Remote repositories facilitate collaboration, version tracking, and backup of the codebase.
It helps to work on multiple developers can work on the same project. it's helps you to collaborate with other developers with the help of remote repo you can connect with anyone globally you can contribute on open source platforms.
#Task1:
Set your user name and email address, which will be associated with your commits
First, install git in your instance
sudo apt-get install git init
then you can check that git is installed or not with the help of this command
git --version
Now create a username and email address
git config --global user.name "Enteryourname"
git config --global user.email "Enteryouremail"
#Task2:
Create a repository named "Devops" on GitHub.
Follow these steps to create a repository named "Devops" on GitHub:
Log in to your GitHub account. If you don't have one, sign up for a new account at github.com/join.
Once you're logged in, click on the "+" sign in the top-right corner of the GitHub website.
Select "New repository" from the dropdown menu. This will take you to the "Create a new repository" page.
On the "Create a new repository" page, provide the following information:
Repository name: Enter "Devops" as the name for your new repository.
Description (optional): You can add a brief description to provide more information about the repository.
Visibility: Choose whether you want the repository to be public (visible to everyone) or private (visible only to you and collaborators). Note that private repositories are available on paid GitHub plans.
Once you have provided all the necessary details, click on the green button labelled "Create repository."
Your new repository named "DevOps" will now be created on GitHub.
Connect your local repository to the repository on GitHub.
Follow these steps to connect your local repository to the repository on GitHub:
Open a terminal or command prompt on your local machine.
Add the remote URL to your local repository using the following command:
git remote add origin https://github.com/sutish/Devops.git
- Verify that the remote URL has been added successfully by running:
git remote -v
Create a new file in Devops/Git/Day-02.txt & add some content to it
Now go to the DevOps folder/directory
cd DevOps/
Now create another folder/directory and create a text file and some content inside the file.
mkdir Git
cd Git/
vi Day-02.txt
welcome to DevOps
esc
:wq
to check the file status use the command "git status" With the help of this command you can file is committed or not
git status
git add .
git status
After the check status of the file the commit your file this commit will show on your GitHub account there will show also the user name who commit to that
git commit -m "this is first commit"
git status
you can check the file comment with the help of "git log " where you will see your commit id 40alphanumeric type git log and paste your commit your will comment
git log
now push your code file on your remote account use of this command ''git push origin main"
git push origin main
To check that your file is now present on your "GitHub account go to the account
and click on your repo. you will your repo name like "DevOps" Click on the you will another folder "Git".
Thank you for reading!
Contact me at :
linkedin: https://www.linkedin.com/in/sutish-pradhan/
E-mail: psutish@gmail.com