Git Basics
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Version Control System:
It was created to make things easier. In order to create websites, the developers used to ftp the file down > made changes locally > and then ftp them back up. But there is a problem if there are some other people working on the project. The other developer could upload the same file, could make some changes and upload it back at the same time which caused a complete mess.
That's where Version Control System → Git helps a lot. The files of two different developers get merged into one file. Another big feature is that is works as a Time Capsule. So over time as you make changes to files and you check them into your source control, it keeps a time log so you've got a complete history of all the files and even why they changed. You can see all the different versions in version control.
Repository Locations:
Up until recently most version control systems used Central Repository but this means that if you have multiple people and they make changes and commits and store that in history it all goes in one central repository - one server. Git has a Distributed Repository. This means that everybody has a complete copy of the repo.
Plus is you can make commits very quickly, you can work offline and everybody has a complete copy so if one gets destroyed, everybody has a copy. Unlike working with the Central Repository, if you lose all your backups and the server goes down, there is going to be a serious issue.
Working with Git:
Most people work with Git using command lines.
Official Git site to download it is http://git-scm.com/
To know the widely-used commands just type git help in the command line and it will give you the list of the commands.
If you want to get something specific, then git help and then the command you need like git help config
Starting a Repo:
After installing Git, you are ready to work on your repo. We are gonna need a Directory: mkdir store, then we are gonna into this directory cd store and we can work on some files at this point. When we are ready to start we simply type git init. This initializes the empty local git repository.
Git Work Flow:
Jane (user) creates a README.txt file. It is untracked for now.
When we are ready to start tracking that file, we add file to Staging area. Getting ready to take a picture
Then we are going to create our first commit. A snapshot of those on the Staging
then
If we modify the file README.txt and add a Licence
Add both files to Staging
And commit changes
So this is the workflow of the Git. You do a little bit of work, stage it and commit.
Important commands:
$ git status to check what's changed since last commit
to start tracking it we first need to add it to the Staging area
$ git add README.txt
and then
$ git status
Now we are ready to make our first commit
$ git commit -m "Create a README." and it is added to the timeline.
if we run
$ git status
at this point, we can see that there is nothing else to commit. There are no other changes or files.
Also it tells us that we are on the Master branch.
We've got 1 main timeline at this point, and it's called Master.
Now Jane modifies the file and adds Licence.
Now there are 2 commits
$ git log
Credits to → CodeSchool













Comments
Post a Comment