Installing Git
Installing Git
VCS Version control systems are a category of software tools that help a software team manage
changes to source code over time.
As you edit to your code, you tell the version control system to take a snapshot of your files.
The version control system saves that snapshot permanently so you can recall it later if you need it.
Without version control, you’re tempted to keep multiple copies of code on your computer. This is
dangerous because it’s easy to change or delete a file in the wrong copy of code, potentially losing
work.
Version control systems solve this problem by managing all versions of your code but presenting
you with a single version at a time.
If you google "what is git", you will probably see the definition for "an unpleasant or contemptible
person."
Thankfully, Git is much better than that. According to the Git documentation:
Git is a free and open source distributed VCS designed to handle everything from small to very
large projects with speed and efficiency.
In plain English, Git is a tool that allows developers to track versions of their code over time. It
does this by creating "snapshots" of the current state of the code base whenever you tell it to.
Git is essential when collaborating with other developers to ensure that previous "snapshots" of the
code can be revisited if necessary.
For example, if you are working on the code and accidentally break the app, it's much easier if
you're using Git and can simply roll back to a previous version of the code.
Having a distributed architecture, Git is an example of a DVCS (hence Distributed Version Control
System). Rather than have only one single place for the full version history of the software as is
common in once-popular version control systems like CVS or Subversion (also known as SVN), in
Git, every developer's working copy of the code is also a repository that can contain the full history
of all changes. In addition to being distributed, Git has been designed with performance
, security and flexibility in mind.
Installing Git
Git isn’t usually set up by default on your computer, so you need to install and configure it before
you can start using it to manage your code.
It’s important to keep Git up to date, just like all the other software on your machine. Updates
protect you from security vulnerabilities, fix bugs, and give you access to new features.
The recommended method of installing and maintaining Git is provided for three major platforms
below :
Removing Files
Let’s say that you have added files to Git and you do not want it to track.
In such a situation, you tell Git to stop tracking them.
Yet, running a simple git rm will not only remove it from Git, but will also remove it from your
local file system as well! To tell Git to stop tracking a file, but still keep it on your local system, run
the following command:
Removing Files
Let’s say that you have added files to Git and you do not want it to track.
In such a situation, you tell Git to stop tracking them.
Yet, running a simple git rm will not only remove it from Git, but will also remove it from your
local file system as well! To tell Git to stop tracking a file, but still keep it on your local system, run
the following command:
git rm --cached [file_name]
Committing Changes
Once you have staged your files, you can commit them into Git.
Imagine a commit as a snapshot in time where you can return back to access your repository at that
stage. You associate a commit message with every commit, which you can provide with the -m
prefix.
git commit -m 'first commit'
Files status
Git sees every file in your working copy as one of three things:
Tracked
A file which has been previously staged or committed.
Untracked
A file which has not been staged or committed.
Ignored
A file which Git has been explicitly told to ignore.
Ignored files are usually build artifacts and machine generated files that can be derived from your
repository source or should otherwise not be committed
*PS : If we have some file that we do not want them to be tracked, we just put it inside
.gitignore file.
Configuration settings
The .gitconfig file contain a list of configuration that affect the behaviour of git command, so
in order to manipulate it, we use the command git config <configuration> , so to
change the name and email used by git to identify the user we use the following command (PS.
change YOUR.NAME and YOUR.EMAIL with your own values.)
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL"
Many times you may be finding yourself typing git commands over and over. Things like git
add, git init and git status are commands you will be typing many times, so it may be
useful to make a shortcut, or alias, which you can type so that you do not need to type the entire
command. To create a temporary alias, which will last as long as your terminal session is open, you
can type:
git config alias.KEYBOARD_SHORTCUT COMMAND
So if we wanted to type git st and have that be the same as git status we would type git
config alias.st status. Now we can type git st and it should output the same as git
status.
If you would like your alias to be a part of your global configuration, add the --global
command after git config. For example, to alias git i to git init globally, you would
type git config --global alias.i init.
In short, Git is a Version Control System. GitHub is an online platform for hosting and sharing
code, text files and even more complex file forma
GitHub provide a great way for you to store your code in a remote
location (in case something happens to your local machine). It's a
fantastic way to collaborate with other developers both privately
and publicly.
Many large open source projects are hosted on GitHub, which makes
it very easy to examine the code both on GitHub and locally.
In the next couple of chapters, we will learn how to move code
from our local repository to a remote repository on GitHub using
the push command, as well as retrieve code from a remote
repository on GitHub using the pull command.
We'll also learn about GitHub specific concepts like forking and
pull requests.
Want to get a sense for how pervasive GitHub is in the development community? Here are some
projects you may have heard of that are hosted there:
If you don't have an account with GitHub yet, head to github.com and create an
account. Signing up is easy!
Be sure to use whatever email address is in your .gitconfig for your email
address when you sign up with GitHub.
If you'd rather sign up with a different email address, change your .gitconfig
accordingly. You'll run into some minor annoyances if there's a mismatch between
the email address in your GitHub profile and the email address in your
.gitconfig.
GitHub