What is Git?
Git is a version control system that serves as a platform for code management where different users working on the same projects can collaborate to share and merge the changes into the same projects. In short, it acts as a tool to track all the file changes where different users can collaborate to work together.
What is GitHub?
Github is a web based hosting service for Git repositories. It provides an open source platform where developers can store their git repositories remotely, making it easier to collaborate with others and access their codes from anywhere. Developers can choose to keep their repositories public or private based on their preferences and project needs.
What is Version Control? How many types of version controls we have?
Version Control is a system that saves each changes made by a file in the form of versions. It stores all the changes of the file in different and unique versions so that if anyone wants to go back to the previous versions, then they can easily go back, make their changes if required which would be again saved in a different version and if not they can switch back again to the latest version. This becomes helpfuul for the developers as they can revert back to the previous versions if they have made any mistakes.
There are two type of version control-
i) Centralized Version Control System(CVCS): It 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. Example: Subversion and Perforce.
ii) Distributed Version Control System(DVCS): It allows developers to clone an entire repository into their local where each developer can work on the independent items. It means all the previous versions and all the branches are copied into their local system where developers can work on their own branches and once their work is completed they can push back their changes and if any conflicts arise they can fix and merge their latest code into the main repository.
Why use distributed version control over centralized version control?
We use distributed version control over centralized version control because of the following advantages -
Better Collaboration - Since, each developer has a separate copy of the main repository, they work individually and push their changes to the main repository by collaborating with other team members. They resolve issues if there are any and commit the correct version of code to the main repository. 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.
Greater flexibility - Since, developers have their code in local, they can work offline and commit their changes once they have 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.
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.
Enhanced security - In a DVCS, the repository history is stored on multiple servers and computers and hence it has multiple data backups. If the central server in a CVCS goes down or the repository becomes corrupted, it can be difficult to recover the lost data.
Task:
Install Git on your computer - You can install it from the official website - https://git-scm.com/downloads
Create a free account on GitHub - You can sign up at https://github.com/
Basics of Git
Open your terminal and try out these basic commands:
Commands | Definition |
git init | It is used to initiate an empty repository. |
git status | It is used to get the current status of the file |
git add filename | It is used to stage the file |
git rm --cached filename | It is used to unstage the file |
git commit -m "message" | It is used to commit the file with a proper message written inside double quotes |
rm filename | It deletes(removes) the file |
git restore filename | It restores the deleted file |
git log | It displays all the versions and history of the file in details |
git log --oneline | It displays only the commit id along with the commit message |
git log --oneline --pretty | It is the same as "git log" except the commit id is shortened |
git config --global user.name="username" | It is used to set the global git username |
git config --global user.email="email" | It is used to set the global git email |
git checkout -b branchname | It is used to create a new branch and switch it to the created branch |
git master | It is used to switch to the master branch |
git branch | It is used to show all the branches inside the repository |
git push | It is used to store the local changes to github |
git pull | It is used to share the branch changes of github to local |
git fetch | It is used to share all the branch changes of github to local |
git clone url | It is used to copy the github repositoy to local |
git remote -v | It is used to view the remote repositories associated with the local Git repository. |
Thanks for reading!
~Shilpi