What is Git and why is it important?
Git is a version control system that is popularly used for managing source code for our software development projects.
We can use git for version control for any set of files and coordinate work on those files among multiple people. Multiple people can contribute to our code and we can work together to improve the speed and reduce the errors.
One of the advantages of using git is we can check who made the changes to the file and you revert those changes at any time as per your need.
For Example, You are working on a project so every people in your team can share their changes and we can merge all the changes made by the different people from different locations into a single version of the file this is also called distributed version control system.
Difference between Git and GitHub?
Git is a version control system that is used to manage source code for software development projects. Git is a command-line tool that helps developers manage changes to their code over time. It lets them work on code with other people, create backups of their code, and review changes made by others.
With Git, developers can create different versions of their code, called branches, and then merge them back together when they're ready. It's a useful tool for anyone who wants to keep track of their code changes.
GitHub is a web-based hosting platform for Git repositories where people can store their code using Git for version control. By using GitHub, developers can work together on coding projects even if they're in different parts of the world. It's a really useful tool for anyone who wants to collaborate on coding projects and keep their code organized in one place.
GitHub provides a graphical user interface (GUI) for Git, making it easier for developers to use Git without needing to use the command-line interface.
In simple words, Git is a version control system used to manage source code, while GitHub is a web-based hosting service and centralized platform for managing Git repositories.
Difference Between the Main Branch and Master Branch?
In Git, the "main" branch and the "master" branch both refer to the default branch in a Git repository.
However, I just wanted to mention that there's this thing going on where some people are suggesting we use the word "main" instead of "master" in certain contexts. The reason behind this is that there are concerns about the term "master" being potentially problematic in certain social and cultural contexts.
In terms of functionality, there is no difference between the "Main" branch and the "Master" branch. They both serve as the default branch and are used as the base for creating new branches in a Git repository. The only difference is the name itself. The choice of which term to use comes down to personal preference and cultural sensitivity.
What is the difference between local & remote repositories?
A local repository is a copy of a repository that is stored on your local computer. You can make changes to the files in the local repository, create new branches, and commit changes to the repository without affecting the original repository. This is mainly used for development, testing, and debugging.
A remote repository is a copy of a repository that is stored on a remote server so that developers can collaborate and share changes. To make changes developer needs to clone it or pull the repository to local and after the changes are made the developer can push it to the remote repository.
In summary, a local repository is a private copy of a repository that you work on locally, while a remote repository is a shared copy of the same repository that is stored on a server and can be accessed by multiple users.
How do you create a new repository on GitHub?
To create a new repository on GitHub, you can follow these steps:
Create a GitHub account and log in to your GitHub account.
Click on the "+" sign and click on the new repository
Then give your repository a name and description
Choose public or private. Public repositories are visible to everyone, while private repositories require access.
Select "Initialize this repository with a README" if you want to add a Readme file to the repository.
Click the "Create repository" button and it is successfully created.
Tasks:
Create a repository named "Devops" on GitHub
Create a new repository on GitHub and clone it to your local machine.
I have created the "Devops" repository.
Navigate to the directory where you want to store your new repository.
Run the command
git clone
followed by the URL of the repository.git clone
https://github.com/prshende/Devops.git
Git will create a new directory with the name of your repository and clone the repository to your local machine.
Set your user name and email address, which will be associated with your commits.
So for this use the below commands,
git config --global user.name "Developer1"
git config --global user.email "developer@gmail.com"
This is used to check who made the changes,
Create a new file in Devops/Git/Day2.txt and commit it.
Create the Git directory and under this create, day Day2.txt and some content to it then use the below commands,
git add Day2.txt
: This is used to stage the filegit commit -m "First commit" Day2.txt
: This is used to save changes to the local repository.git status
: This is used to view the status of the filegit log
orgit log --oneline
: This is used to view all commits.Push the changes back to the repository on GitHub
Here use the below commands,
git remote -v
: To check the URLs.But if you don't have any URLs then use the below command to connect local to remote,
git remote add origin
https://github.com/prshende/Devops.git
Then run the below command,
git push -u origin main
Thank you for reading the blog.
Suggestions are always welcome. Thank you !!