Git is a free and open source software for version control, that is designed to handle all kinds of projects.
For example, let's consider people A and B working on the same project. Let's assume they are editing the same file.
If A adds some text, and B replaces some text, a problem arises. The same file is being edited by 2 people, and there arrives a clash. The text replaced by B could be one of the dependencies of A's text.
Git was introduced into this world, to solve this problem. One can edit the file, the other can also do the same, but these kinds of errors won't occur.
You can install git via checking out this URL: https://git-scm.com/downloads, and then selecting your operating system. Alternatively,
- If your're using Chocolatey in Windows, open Powershell as admin and run this:
choco install git -y
- If you're using Linux, run this (according to your distro):
sudo apt install git -y (Debian based) sudo pacman -Sy git (Arch based) sudo yum install git -y (RedHat/Fedora based)
- If you're using macOS with HomeBrew installed, use this command:
brew install git
And now, you're ready to use Git.
Using Git via the GUI offered by GitHub seems easier, but learning the command line is even more easier and it helps you a lot.
Here's how you can use Git with the command line:
git clone url_of_repo(To clone the repository into your system)
git checkout branch_name
(to change to a separate branch)
git checkout -b branch_name(to create a new branch and switch to it)
You can create a file after changing the branch, or make any changes to already existing files.
After editing/modifying the files, you have to push the changes to GitHub.
Note: For the following commands to work, you must be inside that prticular folder. Else, it won't work :)
git add ." ( Here, period is used to push all the files) or
git add -A(same purpose)
git commit -m your_message(to )
git push(to push your changes to the repository)
This might not work during a few situations, so you can use the command which is recommended by Git to use in the terminal.
And, those are the basic methods to use Git. If you master these 5 commands, you won't be needing the GUI to manage files via GitHub.
Publisher: Pranav P