Git is a free, open-source distributed version control system. It keeps track of projects and files as they change over time with the help of different contributors.
Version control is a system that records changes to a file, or set of files, over time so that you can recall specific versions later.
Git helps keep track of changes made to a code. If at any point during coding you hit a fatal error and don’t know what’s causing it, Git allows you to revert back to a stable state. It also helps you see what changes have been made to the code over time.
A repository (commonly referred to as repo) is a collection of source code. A repository has commits to the project or a set of references to the commits (i.e., heads).
A commit logs a change or series of changes that you have made to a file in the repository. A commit has a unique SHA1 hash which is used to keep track of files changed in the past. A series of commits comprises the Git history.
A branch is essentially a unique set of code changes with a unique name. Each repository can have one or more branches. The main branch — the branch where all the changes eventually get merged into - is called the master. This is the official working version of your project and the one that you will see when you visit the project repository at github.com/yourname/projectname.
Every local repository has three different virtual zones. These are:
The working directory is where new files are created, old files are deleted, or where changes are made to already existing files.
Once changes are made, they are added to the staging area. The staging area is also sometimes called the index.
Once the changes are complete, the staging area will contain one or more files that need to be committed. Creating a commit will cause Git to take the new code from the staging area and make the commit to the main repository. This commit is then moved to the commit area.
To get started with Git, go to your terminal and run the following command in your project directory. This initializes a project directory.
Run the following command to add files for Git to track. This will add these files to the staging area.
git add <filename_one>
Run the following command to commit your changes to these files.
git commit -m "<add a commit message here>"
We can push our changes through once we’re done.
Making any more changes in the master branch will require these changes to be committed again.
View all Courses