0% found this document useful (0 votes)
34 views

Git GitHub

This document provides an introduction to Git and GitHub. It begins with the author's name and details. It then discusses what version control systems are, why they are important, and the different types including local, centralized, and distributed. It provides an overview of what Git is, what GitHub is, and defines a repository and its structure. It lists and explains some common Git commands like add, commit, push, clone, branch, checkout, merge, etc. It describes the concepts of branches and merging in Git.

Uploaded by

Sachin Rawat
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Git GitHub

This document provides an introduction to Git and GitHub. It begins with the author's name and details. It then discusses what version control systems are, why they are important, and the different types including local, centralized, and distributed. It provides an overview of what Git is, what GitHub is, and defines a repository and its structure. It lists and explains some common Git commands like add, commit, push, clone, branch, checkout, merge, etc. It describes the concepts of branches and merging in Git.

Uploaded by

Sachin Rawat
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 30

Introduction To Git And GitHub

• Name –Sachin Rawat


• Section – A
• University Roll No – 2018675
• Student ID – 20011550
Content
• Version control system
• Need of VCS
• Types of VCS
• What is Git
• What is Git Hub
• What is repositiory
• Repositiory structure
• Git commands
• Branches concept in git
• Merging concept in git
• Fast forward merge
• 3-way merge
• Have you ever made a change to code, realised it was a mistake and wanted to revert
back?

• Have you ever had to maintain multiple versions of a product?

• Have you ever wanted to review the history of some code?

• Have you ever wanted to see how much work is being done, and where, when and by
whom?

• Have you ever wanted to share your code, or let other people work on your code
simultaneously?

• Have you ever wanted to experiment with a new feature without interfering with
working code?
Version Control System
• Version control systems are software tools that helps in recording changes
made to files by keeping a track of modifications done to the code. 

• Version tracking and branching

• Tagging

• Restoring Previous Version

• Collaboration
Why Version Control system is so
Important?
• As we know that a software product is developed in collaboration by a group of developers
they might be located at different locations and each one of them contributes in some specific
kind of functionality/features.

• So in order to contribute to the product, they made modifications in the source code(either by
adding or removing).

• A version control system is a kind of software that helps the developer team to efficiently
communicate and manage(track) all the changes that have been made to the source code
along with the information like who made and what change has been made.

• A separate branch is created for every contributor who made the changes and the changes
aren’t merged into the original source code unless all are analyzed as soon as the changes are
green signalled they merged to the main source code. It not only keeps source code organized
but also improves productivity by making the development process smooth.
Types of Version Control Systems: 
 
• Local Version Control Systems

• Centralized Version Control Systems

• Distributed Version Control Systems


Types of Version Control Systems: 
• Local Version Control Systems:  It is one of the simplest forms and has a database that kept all
the changes to files under revision control. RCS is one of the most common VCS tools. It keeps
patch sets (differences between files) in a special format on disk.

 
• Centralized Version Control Systems: Centralized version control systems contain just one
repository and each user gets their own working copy. You need to commit to reflecting your
changes in the repository. It is possible for others to see your changes by updating. 

• Distributed Version Control Systems: Distributed version control systems contain multiple


repositories. Each user has their own repository and working copy. Just committing your
changes will not give others access to your changes. This is because commit will reflect those
changes in your local repository and you need to push them in order to make them visible on
the central repository. Similarly, When you update, you do not get other’s changes unless you
have first pulled those changes into your repository. 
WHAT IS GIT
• Git is a free and open-source distributed version control
system for tracking changes in source code

•Initially designed and developed by Linus Torvalds for Linux


kernel development in 2005.

• No need to connect to central server

• Can work without internet


What GIT is about?
• 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.

• Git relies on the basis of distributed development of a software where more than one developer
may have access to the source code of a specific application and can modify changes to it which
may be seen by other developers..

• Initially designed and developed by Linus Torvalds for Linux kernel development in 2005.

• Every git working directory is a full-fledged repository with complete history and full version-
tracking capabilities, independent of network access or a central server.

• Git allows a team of people to work together, all using the same files. And it helps the team cope
up with the confusion that tends to happen when multiple people are editing the same files.
What is Repository

•Your repository is where you’ll organize your project.

• You can keep folders, files, images, videos, spreadsheets and


anything else your project needs.

• Before you can work with Git, you have to initialize a repository
for your project and set it up so that Git will manage it.
Git Repository Structure
• It consists of 4 parts:

• Working directory : This is your local directory where you make the project (write code) and
make changes to it.

• Staging Area (or index) : this is an area where you first need to put your project before
committing

• Local Repository : this is your local repository where you commit changes to the
project before pushing them to central repository on Github. This is what is provided by
distributed version control system. This corresponds to the .git folder in our directory.

• Central Repository : This is the main project on the central server, a copy of which
is with every team member as local repository.

• All the repository structure is internal to Git and is transparent to the developer.
Commands
• These are a list of few commands that you can use frequently on github(git bash) 
 
• git help
• Take help from github help section for different commands and other errors 
 
• git config
• To set the basic configurations on github like your name and email. 
 
• git config –-global user.name “Sachin Rawat”
• Sets configuration values for your user name on git. 
 
• git config –-global user.email “[email protected]
• Sets configuration values for your user email on git. 
Commands
• mkdir store
• Create a directory if not created initially. 
 
• cd store
• To go inside the directory and work upon its contents. 
 
• git init
• To create a local git repository for us in our store folder.This
will help to manage the git commands for that particular
repository. 
 
Commands
• git commit -m “Created a Readme.txt”
• To commit our changes(taking a snapshot) and providing a message to
remember for future reference. 
 
• git log
• To check the history of commits for our reference. 

• git status
• To see whats changed since last commit.It shows all the files that have been
added and modified and ready to be commmitted and files which are untracked 
Commands
• Different ways to use add command: 
 
• git add
• To add a specific list of files to staging area. 
 
• git add –all
• To add all files of current directory to staging area. 
 
• git add *.txt
• To add all text files of the current directory to staging area.
Commands
• git remove rm
• To remove a remote from our local repository. 
 
• git push -u origin master
• To push all the contents of our local repository that belong to master
branch to the server(Global repository). 
 
• git clone https://github.com/sachin123/MyAlgorithms.git
• To clone or make a local copy of the global repository in your system 
(git clone command downloads the repository and creates a remote
named as origin which can be checked by command – git remote -v). 
 
Commands
• git branch Testing
• To create a new branch named as Testing. 
 
• git branch
• To see all the branches present and current branch that we are
working on. 
 
• git checkout Testing
• To switch to branch Testing from master branch. 
 
Commands
• git merge Testing
• To merge Testing branch with master branch. 
 
• git branch -d Testing
• To delete Testing branch. 
 
• git checkout -b admin
• To create a new branch admin and set it as current branch. 
 
• git add Readme.txt
• To add a file Readme.txt to the staging area to track its changes. 
Branching
• Git branching allows developers to diverge from the production version of
code to fix a bug or add a feature.

• Developers create branches to work with a copy of the code without


modifying the existing version.

• You create branches to isolate your code changes, which you test before
merging to the main branch .

• There is nothing special about the main branch. It is the first branch made
when you initialize a Git repository using the git init command.
Branching
• As you create commits in the new branch, Git creates new pointers to track the
changes.

• The latest commits are now ahead of the main branch commits. As you continue to
make commits, each branch keeps track of its version of files.

• Git knows which branch you have checked out by using a special pointer called
HEAD.

• When you create a new branch, Git doesn’t immediately change the HEAD pointer
to the new branch. You’ll see HEAD in the commit history when you create
branches and view the commit log.
Branching
• When you create a commit, Git identifies that snapshot of files with
a unique SHA-1 hash. When you initially create a branch, Git creates
a new pointer to the same commit the main branch is currently on.

• This branching function is what makes Git really powerful. Multiple


people create separate branches to work on their code and merge
their changes into the main branch.

• Branches are meant to be temporary and should be deleted when


work is completed.
Merging Branches
• Once you’ve completed work on your branch, it is time to merge it into
the main branch. Merging takes your branch changes and implements
them into the main branch.

• Depending on the commit history,

• Git performs merges two ways:


• fast-forward and three-way merge.

• Let’s examine both of these based on the branches and commit history
Fast forward merge
• Fast forward merge can be performed when there is a direct linear path from the source
branch to the target branch. In fast-forward merge, git simply moves the source branch pointer
to the target branch pointer without creating an extra merge commit.

• Let us look at an example implementing fast-forward merge.

• We have a master branch with 3 commits.

• Next, we create a branch called feature branch. In git a branch is nothing but a pointer to a
commit. At this point both feature and master are pointing to the same commit.
Fast forward merge
• Now let us switch to the feature branch and do a couple of commits. Now
we need to bring the changes to the master branch. There is a linear path
from feature to master.

• In order to merge the changes to the master branch, all git has to do is to
change the pointer of master forward. This is what we call fast-forward
merge.
3-way merge
• Let us look at an example of a 3-way merge. In this example, the
Feature branch is two commits ahead of the Master branch.
3-way merge
• Before we merge it with Master, let us say we have added an
additional commit to the Master as shown in the below diagram.
3-way merge
• Due to the commit performed on the Master branch, both our
branches Master and Feature are now diverged.

• This means we have some changes in the Master branch that is not present in


the Feature branch. If we perform a merge in this case, Git cannot move the master
pointer towards the Feature branch.

• If git simply moves the Master pointer to the Feature pointer, then the latest
commit C6 performed on the Master branch will be lost.

• So how do we perform a merge if the branches are diverged?


3-way merge
• When we want to merge the branches that are diverged, Git creates a new commit
(Merge Commit) and combines the changes of these two branches as shown in the
below diagram.
• To merge the changes from both the branches, Git looks at the three different
snapshots - the before snapshot and the after snapshots. Based on these
snapshots, Git combines the changes by creating the new commit called the Merge
Commit.

You might also like