Introduction to Git
Git is a distributed version control system for storing and tracking changes in computer files.
This means that git allows many developers to work on the same project without being on the same network.
Git is not a programming language as many new developers do assume. It is only an important tool that every developer should know since its uses will always be found in your entire career as a software developer.
It can be used for programming with Java, c#, c++, JavaScript, python, PHP and all other programming languages so it is not language-dependent.
Git is the most widely used version control system in the world.
It is a distributed and actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.
The key concepts of git
- co-ordinate work between multiple developers.
- Revert back changes in committed files or folders.
- Enable developers to work on both local and remote projects.
The benefits of using git
- Keeps track of all committed code histories.
- Takes snapshots of committed files.
- Allows developers to visit any snapshot.
- Allows developers to delete snapshots.
- Allows developers to create branches in projects.
The Important and Basic Git Commands
git init
: This command tells git hey I want you to keep track of the files in this folder. it allows us to use the git commands.git add
: allows us to add files to the staging area.git rm
: allows us to remove files from the staging area.git commit
: Allows us to take a snapshot of changes in our files.git status
: This command allows us to see the changes that are both tracked and untracked by git and the current branch.git log
: This command allows us to see all the commits in git and the current branch.git pull
: This command is used to fetch and download content from a remote repository and immediately update the local repository to match that content.git push
: is used to upload content from the local repository to the remote repository.git clone
: This command is used to point to an existing repo and make a copy of that repo in a new directory in our local machine.git rm
: allows us to remove files from the staging area.git branch
: allows us to create a branch in our git repository.git checkout
: allows us to switch current branches in git.git merge
: allows us to merge other branches into the current branch.
N/B A repository is just another name for a folder that is initialised with git. N/B Visit the git documentation for the full git commands.
How To Install Git
Git can be downloaded from the Internet and the best part is it’s free, Git can be installed on a variety of operating systems such as Mac OS X, Windows and Linux.
We will consider windows in this course in discussing our concepts while resources will be shared for Linux and Mac OS X:
To start, you need to download your operating system specific Git package; we can get the list of downloadable packages from here.
Go ahead and download the latest stable release relevant to your OS, which you can find on the website, as shown in the following screenshot (Version 2.25.0 was the latest stable release at the time of writing this course) :
How to install Git on Windows
On a Windows machine, the website automatically provides the Download for Windows button.
Upon clicking that, you will be prompted to save the setup file. Choose your preferred location to save the file and you are good to go.
Follow the procedures below to install git on windows:
Double-click on the downloaded setup file to get started with the installation.
The first and second steps of the installation process are self-explanatory. It first greets you with a welcome message and informs you about the “safe to follow” procedures before installation, that is, to close all other opened applications before continuing (just to avoid the remote chance of any shared dll/exe being overridden or a simple case of your system running out of memory, which is required in large amounts whenever you perform an installation). Then it shows you the details about the GNU public license Version 2 by which our Git is governed.
Clicking on the Next button on the screen gets your preferred location for the installation. The default location is inside the Program Files directory of your Windows installation.
After clicking on Next you will be facing a component configuration screen in which you need to select Git Bash Here and Git GUI Here options under the Context menu entries section, as shown in the following screenshot:
These options are going to provide us with quick access to interfaces that we can use to command Git.
Next, we are prompted to select a group name under which shortcuts are placed in the start menu for easy and quick access.
Let us leave it to the default value Git and click on Next.
This brings us to the following screen, in which we select the second option, which says Run Git from the Windows Command Prompt:
This setting is basically for people who will be using command lines to control Git and its activities.
This option is going to allow us to command Git additionally from the native Windows command-line interface DOS. After making the selection, click on the Next button.
That’s about it. Your installer should finish the installation now.
Congratulations! Your Windows machine is now ready to control the versions of any content with Git.
For Git installation on Linux – Download link
For Git installation on Mac OS X – Download Link.
Updating Git via Git
If you already have Git installed, you can get the latest development version via Git itself. git clone https://github.com/git/git
You can also always browse the current contents of the git repository using the web interface.
Conclusion
At the end of this module we have been able to understand git, what it does, it basic commands and finally, we got it running in our machine.