setting up the tone
while working on group project large projects or any projects kyaa aapke man me aise kuchh kaam yaa sawal aaye hai
code me kuch change kiya fir realise huaa ye to galat hai aur fir se purane wale code pe jana chaha ho.
Jo bhi code aap likh rahe ho usko retain kar sako agar lost ho jaaye to ek backup rahe
kisi bhi large code base ki history jaan ni ho when and what changes huye hai isme
kisi aur ke code me contribute karna ho yaa group project me contribute karna ho.
koi new feature add kar ke test karna ho apne software me without interfering with working code.
agar aise sawal hai to uska ek sidha saa jawab hai use version control and source code management tools like git and github
what is version control tool?
version control tools are the tools which help in concurrent development,working together and maintaining history of the work to the software engineers.
what they help in
collaboration
maintaing versions
backups
restoring version
understanding what has happened to the code base over the time
Types
Centralized version control tools
Distributed Version control tools
ex:
distributed vcs :- git,mercurial
centraluzed vcs :- CVS,SVN
Distributed VS Centralized
Centralized | Distributed |
There is one central server and enable team collaboration | It does not use central server that is why we can do multiple works offline like commit changes,create branch,view logs etc. |
failure in the central server will stop all collaboration works | connection is only needed to publish the changes or to get latest changes |
works on two-tier architecture 1. working copy 2. repository | |
works on three-tier architecture 1. Working copy 2. Staging Area3. repository | |
checkout is used to get files from repository to our working copy | staging area is the place where we organise all the files we are going to place in repository and can do staging using git add command |
commit is used to putting files from working directory to repository | we can commit changes from staging area to the repository using git commit |
version control tool that we are more concerned about is git
we can easily download and configure git as it is open source product and free to use
git workflow
modify the file in our working copy
stage the files with changes ,adding snapshot of them in staging area
commit the changes ,it will take the snapshots from staging area aoond publish them to repository
figure depicting workflow of git
Advantages of git
Fast and small
Free and open source
Easier branching
implicit backup
security
Work cycle of git
important terminology
Tree :- itas object , which represent a directory.
commits :- they hold current state of the directory
Branches :- They are required to create another line of developement for adding every new functionality a new branch can be created
clone :- it creates an instance (blue print or copy ) of the repository
pull :- pull option copies the changes from remote repository to local environment
push :- it copies changes from local to remote
head :- a pointer which always point to latest commits in the branch
stash :- it is an operation used to put current work copy to back stage for a small period of time
Important git commands and works
Setting Up repository
git init
git init is used to create a new repository.it creates a new .git sub directory in the projects directory which contains all git meta data for that new repository.
a --bare option is used with git init to create a bare repository(a repo which does not have working tree/directory).git clone
git clone is a command which is used to create a copy of the repository at new directory, any new location
git clone <repo> <directory> :- this command is used to clone a repo to specified directoryshallow cloning is used to get specied version of a repository . agar koi aisaa repo hai jhaa bahut hi jyada commits ho rhe hai aur hame most recent commit yaa las 2 yaa last 3 (here last means most recent) commits tak hi repo clone karna hai to we use shallow cloning . it is done by
git clone -depth=n <repo>:- where the value of n given to d will specify version which we want
Dealing with changes
git add :- this command is used to add the chnages made in the local repo to the staging area
git commit :- it a command used to commit the changes to remote repository. it commits whole snapshot from staged area not only the differences . it has multiple options with it, they are:
git commit -a :- Commit a snapshot of all changes in the working directory. This only includes modifications to tracked files.
git commit -m :- allows to add commit messagegit commit -amend :- ammed the previous commited repository instead of creating a new one.
git diff :- it is used to get differences in two repositories or two commits.
git stash :- jab aap kisi ek feature pe kaam kar rhe ho but achanak se koi dikkat ke wajah se urgent koi aur branch ya code pe kaam karna pad jaaye to aap apne current work ko stash me store kar sakte hai .
these are commands for changes
inspecting a repo
- git tag and git blame commands are used for inspecting
undoing changes
git clean :- used to remove untracked files and repository
we can use multiple options to specify paths and other things we can also make it interactive using git clean -digit revert :- it creates a new commit which undoes all the changes made in previous (only one) commit .(it actually takes repo one commit back )
git reset:- it takes back to a previous commit discarding changes mmade after that commit
git rebase <base> :- rebase the current branch to <base>.<base> can be commit id , branch, tag or a relative reference to head.
other important commands
git remote :- it help us to create a view and delete connection with other repositories. it also list the remote connections you have with other repositories
git remote -v will aslo show urls of all connections you have
git remote add <name> <url> :-Create a new connection to a remote repository. After adding a remote, you’ll be able to use <name> as a convenient shortcut for
<url>
in other Git commands. example :- (i). git remote add origin <url>(ii). git push origin master , here instead of providing url of repo we have given the name origin in push command
git fetch :- git fetch command downloads commits,files from a remote repo to your local repo.
to fetch only specified branch we use, git fetch <remote> <branch>
git push :- add the local repo to remote .
git pull :- it downloads the files from re,ote repo and merge it with local repo. it first runs fetch command and then merge command locally.
git branch :- used to create branch . ex:- git brach feature , it will create a new branch called feature.
git checkout :- used to navigate through branches . ex:- git checkout feature , it will take you to brach called feature.
git merge:- used to merge a branch to another branch . use git status command to make sure that the head is pointing to the position where you want to merge.if head is not at right position we must checkout to right branch before merging.
git log :- this is used to log version history.
git status :- this shows all modified files which are not committed
This conclude the basic knowledge about git and version control
THANK YOU FOR READING