Git
Git
-- What is Git
-- SVN Vs Git
-- Git Architecture
What is Git?
Let's look at the problem #1 that we get when we do not use version control
system, so let's say....
you have a computer and you are writing code on that computer, so the code files
will be saved locally on that computer's hard disk, but what if your hard disks
crashes, or your computer has some kind of problem in that case whatever the
code you have written is lost..
Problem #2
So Problem #2 is if multiple people wants to contribute the code, then they can't
do it if it is on one computer.
let's say 2 people have they own computer's and they want to work on same code
how do they do that, they have to transfer files using pen drive from one
computer to another and they have to code merge manually.
Problem #3
Let's say you have code and it is working fine, and you are making on
announcement like fixing some bugs, you made some changes and let's say it
does not look good. so you want to go to previous version of your code but there
is no way if you have code on your computer because the simple file system does
not give you version tracking.
* so you have all these kind of different different issues especially when you
working on bigger code of sample project.
In version control system the code is saved on cloud, cloud is basically some
remote machine, which is much better than your local computer and it is
guarantee that you will never loose code from cloud.
so you store your code on the cloud and then you can able to see the files on your
local computer that way if your hardware problem or computer breakdown you
get your code back from cloud.
So problem #1 fixed.
Problem #2 Solution:
Multiple people contributing the same code, you have golden copy of your code
on the cloud so that multiple people can work on form their individual computers
and ten whenever they are adding to push the changes, they will push it to the
cloud.
--Now let's say if they are working on the same function here there is a python
function def sum(a,b): and they both are making changes to the same function
then merge tools available which can help you resolve the conflict.
Problem 3# Solution:
Problem 3# is version tracking, in version control system you have all your
changes tracked on through different versions of the same file.
Let's say you have file Foo.py which has function called sum(x,y); it just returns
a+b, but if you make changes later on and if you save it, it will be saved as version-
2, version-3 and so on.
so at any given point of time, you feel like want to go back to the previous old
version which was working okay, you can do it very easily.
For example This is my Central Repository means all people finally working on the
code, that code will go for the Development and Testing, QA environment and
Production environment , okay, whatever we have remote server is there that
remote server will go for the final deployment.
-- if i have different peoples are working on this code, okay for the same project,
now what happened in SVN, they don't have to see in other codes, okay, they
have only the snapshot of the code, full project won't have in the developers
machine.
and also what are the operations they want to do they will depends on the
internet and they will go for the every commit for the server, now SVN is the
remote server, every commit like as
gitadd
commit
check
push
log
what are the operations they are going to do, what are the commands they run
everything will work on the Remote server not in the local, that's why 10 people's
are working on the same project , all are hitting every time then the server may
be going to down or crashing, that type of issues we are facing with the SVN and
also every time when the people commit any command running the internet is
mandatory in this sub version control system.
SVN:
As you can see in the above diagram, every programmer maintains a local
repository on its own, which is actually the copy or clone of the central repository
on their hard drive. They can commit and update their local repository without
any interference.
They can update their local repositories with new data from the central server by
an operation called “pull” and affect changes to the main repository by an
operation called “push” from their local repository.
The act of cloning an entire repository into your workstation to get a local
repository gives you the following advantages:
All operations (except push & pull) are very fast because the tool only
needs to access the hard drive, not a remote server. Hence, you do not
always need an internet connection.
Committing new change-sets can be done locally without manipulating the data
on the main repository. Once you have a group of change-sets ready, you can
push them all at once.
Since every contributor has a full copy of the project repository, they can share
changes with one another if they want to get some feedback before affecting
changes in the main repository.
If the central server gets crashed at any point of time, the lost data can be easily
recovered from any one of the contributor’s local repositories.
Go to https://github.com/join
$ mkdir jmsgit
$ ls -a
./ ../
--So you have a directory that contains one file. Run git init in order to create a git
repo from that directory.
$ git init
Initialized empty Git repository in C:/Users/basani/jmsgit/.git/
* we did git init means we are initializing our git file as git project then .git folder
has been created for us.
--do ls -ltra then See .git file has been created right when we have .git file that
project is called as git project.
$ ls -ltra
--then open git bash and do git add
$ git add .
$ git remote -v
--then go to github account and copy the git remote add origin command and
paste in gitbash
$ git remote -v
origin https://github.com/srinubasani/jmsgit.git (fetch)
origin https://github.com/srinubasani/jmsgit.git (push)
--now refresh the browser okay, see the Sample.txt has been reflected here.
** lets go and check Github account Helloworld.sh file also reflected there.
Github
--Developer A and B is working on same file, that is either class, shell script,
python script whatever it may be.
--for example that file name is Sample.txt now what happened these two
developers are taking latest code and pull this code.
--now in the Sample.txt file what are the content is there like as below
sample.txt----file
this is sample----content
now what happened is developer A has written the code in the sample.txt file like
this is my second line.
Sample.txt----file
this is my second line--content
and developer B has pushed to github so that sample.txt file contains 2 lines but
developer A is having only first line like as this is sample.
and developer A also added one line like as this is my code and developer A is
trying to push this content to github but github say's Mr. developer A you did not
have latest code, first pull latest code using git pull command, once you pull the
code and try to add code in second line but developer B already added code in
the second line.
Note: So what we will do is will do it git status so that merge conflicts file will
appear then we have to open this file in vi editor and remove unwanted
characters and next push this code to github.
Note: If both developer's are working on the same file and same line of code then
merge conflicts will be appear.
**first of all what is git branch, when we are using git branch let's discuss these
things, basically this is my remote repository, what is the default branch we have
master, master is the default branch, this master is having all complete projects.
--Now what happened i don't want to modify master branch, some issues came in
the production, okay what they will do is they will create one bugfix branch, after
creating the new branch the complete project will come up here also.
--now what are the changes you want to do, you can do with the bugfix branches,
now modify the code and push the code to bugfix and test this code then finally
this merge bugfix branch to master, after merging what are the code in the bugfix
branch that will be available in the master branch, now this bugfix branch don't
required right because putting one project with two resources is not good then
what we will do is we delete bugfix branch.
--different different teams they create branches for them like as UI developer,
database developers, db backend developers finally they will merge into the
master branch.
Explanation: I have project, under this project i have master branch, master
branch is having complete code, what happened now i deployed code into
production, here what happened the code is not working properly, okay that they
won't modify the code directly into the master branch, what they will do, they will
create branch called bugfix, after creating bugfix branch the code copy is available
into this branch, now what happened will modify code into bugfix branch and test
this code into master branch and master branch is having the latest code then we
will delete bugfix branch.
----Now open github repository and create one branch called future
--now future branch also having same files right, now how can i pull future branch
to my local.
--open gitbash
$ git branch --list
we are having only one branch that is master
$ git branch -a