The Version Control System – Git and
GitHub
What is Git?
Git is open free
source distributed control system designed to handle everything from small
projects to large project with speed and efficiency. Git actually create local
repository on our computer.
Why should we learn Git?
Git is most popular version control system. Let’s talk about
manage our projects files. Project can have so many files like html, xml. Git keep
track of every change in our application. If we want to see out code which we
have written a month ago then Git is very helpful and we can see what date and
time we have made change to our data.
Git Features-
1. Compatibility-
Git is compatible with all the operating systems. Git repositories can be
accessed from other version control systems.
2. Collaboration-Git
is widely used because it supports collaboration. Git helps compare, track and merge
changes in a code. Git enhances productivity. Git supports continuous changes
and merge multiple changes together.
3. Feature branches
–Git allows make changes in the project without affecting the original version.
Any branch can be changed and merge together in master branch.
4. Lightweight- Git
stores data from centre repositories to local repository while cloning is done.
It is much efficient to fetch data from local repository.
5. Save Data – GitHub
eliminates the risk of losing data of an individual developer’s system crash as
it keeps the data on a central repository.
How it works
Step 1-Firstly
to start with git, we have to download Git on our computer. After installation, you will be able to see a
folder Git bash and Git GUI. Open Git bash where you can write all the
commands.
(Git – version) Print
the git suite version .
(Git config ) Get and
set repository or global option
Step 2-Create a local Git Repository and initialise
the Git repository by git -init command
Step 3 -Add a
new file to repository by using touch command then you can use Git status
command to see the files which git knows exist.
Step 4-(Staging) It controls what’s get committed
, if you have added and modified some files, you need to stage those commits
into the staging area. You can stage individual file and all files at once. It tells
git to put into commit.
By using this command
git add -A
Step 5-(Commit) Nothing
will save in git until we actually commit . A commit is the record of which
files you have changed since the last time you made a commit.
GitHub service – In GitHub, there is the
remote repository that is created on server. GitHub is Git repository hosting
service. GitHub is a website that hosts Git Repositories online, making it
easier for developers to share code.
Step 1- Create a
new repository on GitHub
Step 2- Push a
branch to GitHub by using this command-
git push origin master
Step 3- Create a
pull request (PR request)
Step 4- Merge
pull request
Step 5- Get
changes on GitHub back to your computer by using this command-
git pull origin master
Let’s take an example, Suppose we go on holiday for a week
.Our co-worker make a change. We see new commits. Then, we can pull changes to
our local machine by this command- (Git pull origin master) so that we can see
at our machine. Now I want to make some changes and stage the change by adding into staging area by this command (git add –A)
and check the status by (Git status) command and commit it by (git commit)
command. If we use this command (git push origin master) , we can see updated
file at remote repository.
Gitignore – There are some
files you don’t want to commit and you say git to ignore some files. If there
are some files, you want to ignore in all repositories on your computer , you
can put them in a global .gitignore file.
What kind of files
you should ignore??
Log files
Files with secrets, Credentials or sensitive information
Dependencies which can be generated from package manager
No comments:
Post a Comment
Please let me know if you have any doubts.