Hey everyone, hope you all are doing good let's get started with the basics of Git and Git Hub...
What is Git π€βοΈ
Git is a version control system that allows you to track file changes and collaborate on files with numerous people. It is most typically used in software development, but it may be used to track changes to any collection of files.
Git is a superhero among developers! It's a useful tool for keeping track of modifications to their projects. Consider it a digital notebook that records every modification you make to your code.
What is Github π€βοΈ
GitHub is a web-based platform that hosts Git-based version management. It is a Microsoft subsidiary that provides all of Git's distributed version control and source code management (SCM) functionalities as well as its own. GitHub is a popular site for developers to share and collaborate on projects, and it is also used to host open-source projects.
GitHub is a giant playground where developers can share their projects with the rest of the world. It's a website that stores Git repositories and allows developers to collaborate and show off their cool inventions/creations.
What is version control βοΈ
Assume you're working on a group project and you routinely save several versions of your document to keep track of changes and prevent losing progress. Version control systems are similar to the magic that powers this process, but they are used for software and other digital undertakings.
Version control is a system that keeps track of changes to a file or set of files over time so that you may go back in time and retrieve specific versions. It lets you revert files to a previous state, return the entire project to a previous state, compare changes over time, check who last edited something that might be causing a problem, who originated an issue and when, and much more.
Types of Version Control Systems π€
There are two main types of version control systems: centralized version control systems and distributed version control systems.
Centralized Version Control System (CVCS) :
A centralised version control system stores all of the project's files and history on a central server. Team members use this central repository directly, checking out files to make changes and then checking them back in. CVCS examples include CVS and Subversion.
Distributed Version Control System (DVCS) :
Version control is taken to the next level with distributed version control systems. Each member of the team has a local copy of the entire project, including its history. This implies they can work alone, even while not connected to the internet. Git and Mercurial are two prominent DVCSs.
In simple words , it 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.
Why do we use Distributed Version Control over Centralized Version Control βοΈ
Better collaboration: Every developer in a DVCS has a complete copy of the repository, including the whole history of all changes. This makes it easier for developers to collaborate because they don't have to constantly contact with a central server to commit their modifications or check what changes others have made.
Improved speed: Because developers have a local copy of the repository, they can commit changes and conduct other version control tasks more quickly because they aren't communicating with a central server.
Greater flexibility: With a DVCS, developers can work offline and commit their changes when they reconnect to the internet. They can also choose to share their changes with a subset of the team rather than pushing them all to a central server.
Enhanced security: The repository history in a DVCS is saved on numerous servers and machines, making it more resistant to data loss. It can be difficult to recover lost data if the central server in a CVCS fails or the repository becomes damaged.
Installing Git π₯οΈ
You can install git on your system by downloading it from the official website https://git-scm.com/downloads
Then Click on the system on which you want to install it and follow the steps as instructed.
Create a free account on GitHub by signing up at https://github.com/
Understanding how Git works using Commands π―
Let's understand how git and github works by creating repository and cloning it to your local machine / system :
After signing up, click on + symbol and click on New repository as shown in above image.
Give the repository name as you line and click on the Add a README file checkbox and then click on create repository
Tadaaπ₯³ you have created your first repo.
To clone the repo to your local machine , click on code and copy the link
Use the command git clone "url" in the terminal to clone the repo on your local machine .
git clone https://github.com/srahul0502/practice.git # go to the repo in your local machine using cd to make changes cd practice
Make the changes you want , suppose i add a text file "demo.txt" and add some text into it and then commit them to the repository using git
Create "demo.txt" using vim or nano , add some txt and save it.
- Here it says that it is not in the staging area so ....
Before commiting it to the repo we add it to the staging area by using git add filename .
# to add it the staging area git add demo.txt # to add all the content present in repo to staging area we can use git add . # to check the status that it is in the staging area or not we use git status
We successfully added the "demo.txt" file on the staging area
Now you can commit the changes to the repo
To commit the changes we use git commit -m "commit message"
# we use -m to add a commit message git commit -m "text file added"
- Here we have successfully commited the text file to the local repo with commit message.
Now , to push the changes to the GitHub repo we use the command git push origin main
# to the push the changes to the main branch of the github repo git push origin main
We have successfully pushed the changes to the Github repo
I hope you understood how to create github account and how to make changes and push them to the github
Stay tuned for more updates
Happy Learning :D