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 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 and 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 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 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 01 Install Git on your computer
For Windows:
Go to the official Git website at git-scm.com/downloads.
Download the latest version of Git for Windows.
Run the installer and follow the on-screen instructions.
During the installation, you can choose the components you want to install. The default settings are generally sufficient for most users.
After the installation is complete, open the command prompt or Git Bash to verify that Git is installed. Type git --version
, and it should display the installed Git version.
Linux:
For Debian/Ubuntu-based systems, open the terminal and use the package manager to install Git. Type sudo apt update to update the package list, then sudo apt install git to install Git.
For Red Hat/Fedora-based systems, open the terminal and use the package manager to install Git. Type sudo dnf install git or sudo yum install git to install Git.
Verify the Git is installed and the version of it:
git --version
Task 02 Create a Free account on GitHub
Below are the steps to create a free GitHub account:
Visit github.com and click "Sign Up."
Choose the "Free" plan and create an account with email or Google.
Verify your email to activate your account.
Complete your profile settings and personalize your GitHub experience.
Optional: Set up an SSH key for enhanced security and convenience.
Create a new repository on GitHub and clone it to your local machine
I can guide you through the process of creating a new repository on GitHub and cloning it to your local machine. Here are the steps:
Creating a New Repository on GitHub:
Go to the GitHub website (https://github.com) and make sure you're logged in to your GitHub account.
Click on the "+" icon in the top right corner of the page and select "New repository."
Fill in the repository information:
Repository name: Choose a name for your repository.
Description: You can provide a short description of your project (optional).
Visibility: Choose whether your repository should be public (visible to everyone) or private (restricted access).
Initialize this repository with: You can select whether to add a README, .gitignore, and a license. These are optional but can be helpful.
Click the "Create repository" button.
Cloning the Repository to Your Local Machine:
Now that you've created your repository on GitHub, you can clone it to your local machine using Git. Here are the steps:
Open your terminal or command prompt on your local machine.
Navigate to the directory where you want to store your local copy of the repository. You can use the
cd
command to change directories.cd path/to/your/desired/directory
Go to your GitHub repository's page and click the "Code" button. You should see a URL under "Clone." It will look something like this:
https://github.com/your-username/your-repository.git
. Copy this URL.In your terminal, use the
git clone
command to clone the repository to your local machine. Replace the URL with the one you copied in the previous step.git clone https://github.com/your-username/your-repository.git
Git will download the repository to your local machine. You might be prompted to enter your GitHub credentials if the repository is private.
Once the cloning process is complete, you will have a local copy of your GitHub repository in the directory you specified.
You've now successfully created a new repository on GitHub and cloned it to your local machine
Make some changes to a file in the repository and commit them to the repository using Git
To make changes to a file in a Git repository and commit those changes, follow these steps:
Navigate to the Repository: Open your terminal or command prompt and navigate to the directory where you've cloned your repository. Use the
cd
command to change to the repository directory:cd path/to/your/repository
Make Changes: Edit the file you want to modify using your preferred text editor or code editor. Make the desired changes to the file.
Check the Status: To see which files have been modified, added, or deleted, use the following command:
git status
This will provide you with a list of changes that have been made.
Stage the Changes: To stage the changes for the next commit, use the
git add
command followed by the filename or a dot.
to stage all changes:git add filename.ext # Replace "filename.ext" with the name of your file
If you want to stage all changes, you can use:
git add .
Commit the Changes: Commit the staged changes with a descriptive message:
git commit -m "Your commit message here"
Replace
"Your commit message here"
with a brief description of the changes you made. Make sure the commit message is informative and describes what you've done in this commit.Push the Changes to GitHub: If you want to update your remote GitHub repository with the local changes, use the
git push
command:git push
This will synchronize your local changes with your GitHub repository.
You have now made changes to a file in your Git repository and committed those changes. Your changes are saved in the Git history, and if you pushed the changes to GitHub, they are now visible in your remote repository as well.
Push the changes back to the repository on GitHub
Open your command prompt or terminal: This is where you type commands.
Go to your project's folder: Use the
cd
command to get to your project folder. For example:cd path/to/your/project
Check what you did: You can see what files you changed using:
git status
Save your changes: First, save your changes by typing:
git add .
The dot
.
means "everything."Explain what you did: Tell Git what you did in one sentence. For example:
git commit -m "I fixed a bug in my code."
Send your changes to GitHub: Push your changes to your GitHub project with:
git push
Log in (if needed): If it's your first time, you might have to log in to your GitHub account.
Wait for it: Watch your terminal until it's done. Your changes are now on GitHub for everyone to see.