What is Git?
Git is a version control system that allows you to track changes to files and coordinate the work on those files among multiple people. It is commonly used for software development, but it can be used to track changes to any set of files.
With Git, you can keep a record of who made changes to what part of a file, and you can revert to earlier versions of the file if needed. Git also makes it easy to collaborate with others, as you can share changes and merge the changes made by different people into a single version of a file.
What is GitHub?
GitHub is a web-based platform that provides hosting for version control using Git. It is a subsidiary of Microsoft, and it offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its features. GitHub is a very popular platform for developers to share and collaborate on projects, and it is also used for hosting open-source projects.
Version Control and types of version controls
Version control is a system that tracks changes to a file or set of files over time so that you can recall specific versions later. It allows you to revert files to a previous state, revert the entire project to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.
There are two main types of version control systems: centralized version control systems and distributed version control systems.
Centralized Version Control System: CVCS uses a central server to store all the versions of a project's files. Developers "check out" files from the central server, make changes, and then "check-in" the updated files. Examples of CVCS include Subversion and Perforce.
Distributed Version Control System: DVCS allows developers to "clone" an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.
Why do we use distributed version control over centralized version control?
Better collaboration: In a DVCS, every developer has a full copy of the repository, including the entire history of all changes. This makes it easier for developers to work together, as they don't have to constantly communicate with a central server to commit their changes or to see the changes made by others.
Improved speed: Because developers have a local copy of the repository, they can commit their changes and perform other version control actions faster, as they don't have to communicate with a central server.
Greater flexibility: With a DVCS, developers can work offline and commit their changes later when they do have an internet connection. They can also choose to share their changes with only a subset of the team, rather than pushing all of their changes to a central server.
Enhanced security: In a DVCS, the repository history is stored on multiple servers and computers, which makes it more resistant to data loss. If the central server in a CVCS goes down or the repository becomes corrupted, it can be difficult to recover the lost data.
Git Workflow
The Git workflow is divided into three states:
Working directory : Modify files in your working directory.
Staging area : Stage the files and add snapshots of them to your staging area by doing git add.
Local Repository : Perform a commit that stores the snapshots permanently in your Git directory. Check out any existing version, make changes, stage them and commit by using the command git commit.
Remote Repository : The
git push
command is used to transfer or push the commit, which is made on a local branch in your computer to a remote repository. Thegit pull
command is a combination ofgit fetch
which fetches the recent commits in the local repository andgit merge
, which will merge the branch from a remote to a local repository.
1. Create a new repository on GitHub and clone it to your local machine
A Repository is a place where you have all your codes or kind of folder on a server.
1. Go to github.com and log in to your account. Click the “New repository” button and then fill details and click Create Repository
2. We need to configure the github account locally. User has to specify their username and email address that will be used with the commits.
2. Make some changes to a file in the repository and commit them to the repository using Git
Initialize a git locally and create a file
Create a file and add it to local repo
After creating the file we have to commit it
Push the changes back to the repository on GitHub by using the command git push. Before pushing the file to the remote repo we have to specify the remote repo using git remote.
Check the GitHub repository after the push.
If there are any changes to the remote repository then we can perform Git Pull to pull changes to local repository.