๐What is Git?
Git is a version control system ๐โจ that allows you to track changes to files and coordinate 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 back 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 own 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.
๐ฐ๏ธ๐What is Version Control?
How many types of version controls do we have? 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 back to a previous state, revert the entire project back 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
๐ฅ๏ธ๐๐Distributed Version Control Systems.
A 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 Apache Subversion and Perforce.
A 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.
Overall, the decentralized nature of a DVCS allows for greater collaboration, flexibility, and security, making it a popular choice for many teams.
๐Task:
Install Git on your computer (if it is not already installed). You can download it from the official website at https://git-scm.com/downloads
Create a free account on GitHub (if you don't already have one). You can sign up at https://github.com/
- Just Sign up using your google sign and follow the instruction as displayed on your screen.
๐Exercises:
Create a new repository on GitHub and clone it to your local machine
โจ Creating a New Repository on GitHub:
Open your web browser and go to GitHub (github.com).
Make sure you're logged in to your GitHub account. If not, log in or create an account.
Click on the "+" icon in the top right corner and select "New repository."
Fill in the repository name, description, choose visibility (public or private), and other settings.
Click "Create repository."
โจ Cloning the Repository to Your Local Machine:
After creating the repository, you'll be redirected to the repository's main page.
Click the green "Code" button. You can choose to clone the repository using HTTPS, SSH, or GitHub CLI. Click on the clipboard icon to copy the repository URL.
โจ Cloning the Repository
Open your terminal or command prompt on your local machine.
Navigate to the directory where you want to clone the repository using the
cd
command.Use the following command to clone the repository (replace
<repository-url>
with the URL you copied):git clone <repository-url>
Press Enter to initiate the cloning process. You might be prompted to enter your GitHub credentials if you're using HTTPS.
Make some changes to a file in the repository and commit them to the repository using Git
Generate a token to access the Github for your local
To generate a personal access token to access GitHub from your local machine. Follow these steps to create a personal access token:
Log in to GitHub:
Make sure you're logged in to your GitHub account in your web browser.
Access Personal Access Tokens:
Click on your profile picture in the top right corner and select "Settings."
In the left sidebar, click on "Developer settings," and then click on "Personal access tokens."
Generate a New Token:
Click the "Generate token" button.
Provide a token description (e.g., "Local Machine Access").
Select the desired scopes (permissions) for the token. For accessing repositories, you'll need at least the "repo" scope. You can choose additional scopes depending on your needs.
Click the "Generate token" button at the bottom of the page.
Copy the Token:
- After generating the token, you'll see it displayed on the screen. Make sure to copy it immediately because you won't be able to see it again.
Use the Token:
- In your local machine's terminal or command prompt, you can use the token to authenticate with GitHub. For example, if you're using Git on the command line, you can replace
<token>
with your actual token:
- In your local machine's terminal or command prompt, you can use the token to authenticate with GitHub. For example, if you're using Git on the command line, you can replace
Push the changes back to the repository on GitHub