SlideShare une entreprise Scribd logo
1  sur  49
Télécharger pour lire hors ligne
Git - GitHub
Presented By:
Nitin Goel
About Git
• Created by Linus Torvalds, creator of Linux, in 2005
– Came out of Linux development community
– Designed to do version control on Linux kernel
• Goals of Git:
– Speed
– Support for non-linear development (thousands of parallel branches)
– Fully distributed
– Able to handle large projects efficiently
Centralized VCS
• In Subversion, CVS, Perforce, etc.
A central server repository (repo)
holds the "official copy" of the
code
• The server maintains the sole
version history of the repo
• You make "checkouts" of it to
your local copy
• You make local modifications
• Your changes are not versioned
• When you're done, you "check in"
back to the server
• Your check in increments the
repo's version
Distributed VCS (Git)
• In git, mercurial, etc., you don't
"checkout" from a central repo, you
"clone" it and "pull" changes from it
• Your local repo is a complete copy of
everything on the remote server
• Yours is "just as good" as theirs
• Many operations are local:
– check in/out from local repo
– commit changes to local repo
– local repo keeps version history
• When you're ready, you can "push"
changes back to server
Version Control
• Version control is a system that records changes to a file or set of files over
time so that you can recall specific versions later.
• Allows for collaborative development
• Allows you to know who made what changes and when
• Allows you to revert any changes and go back to a previous state
• Three of the most popular version control systems are:
 Git
 Subversion
 Mercurial
Git vs Github
• Git is a revision control system, a tool to manage your source code history.
• Github is a hosting service for Git repositories.
Terminology
Version Control System / Source Code Manager
 A version control system (abbreviated as VCS) is a tool that manages different versions of
source code. A source code manager (abbreviated as SCM) is another name for a version
control system.
Commit
 Git thinks of its data like a set of snapshots of a mini file system. Every time you commit (save
the state of your project in Git), it basically takes a picture of what all your files look like at
that moment and stores a reference to that snapshot. You can think of it as a save point in a
game - it saves your project's files and any information about them.
Repository / repo
 A repository is a directory which contains your project work, as well as a few files (hidden by
default on Mac OS X) which are used to communicate with Git. Repositories can exist either
locally on your computer or as a remote copy on another computer. A repository is made up
of commits.
Terminology
Working Directory
 The Working Directory is the files that you see in your computer's file system. When you open your project files up
on a code editor, you're working with files in the Working Directory.
 This is in contrast to the files that have been saved (in commits!) in the repository.
Checkout
 A checkout is when content in the repository has been copied to the Working Directory.
Staging Area / Staging Index / Index
 A file in the Git directory that stores information about what will go into your next commit. You can think of the staging area as a prep
table where Git will take the next commit. Files on the Staging Index are poised to be added to the repository.
SHA(Secure Hash Algorithm)
 A SHA is basically an ID number for each commit. Here's what a commit's SHA might look
like: e2adf8ae3e2e4ed40add75cc44cf9d0a869afeb6.
Branch
 A branch is when a new line of development is created that diverges from the main line of development. This
alternative line of development can continue without altering the main line.
Install Git on Windows
• Download the latest Git for windows installer.
• When you've successfully started the installer, you should see the Git
Setup wizard screen. Follow the Next and Finish prompts to complete the
installation.
• Open a Command Prompt (or Git Bash if during installation you elected
not to use Git from the Windows Command Prompt).
• Run the following commands to configure your Git. These details will be
associated with any commits that you create.
Git Configuration
• # sets up Git with your name
git config --global user.name "<Your-Full-Name>"
• # sets up Git with your email
git config --global user.email "<your-email-address>"
• # makes sure that Git output is colored
git config --global color.ui auto
• # displays the original state in a conflict
git config --global merge.conflictstyle diff3
• git config --list
Associating text editors with Git
• Using Atom as your editor
– Install Atom.
– Open Git Bash.
– Type this command:
git config --global core.editor
“C:/Users/USERNAME/AppData/Local/atom/bin/atom.cmd”
Using Sublime Text as your editor
– Install Sublime Text 3.
– Open Git Bash.
– Type this command:
git config --global core.editor "'c:/program files/sublime text 3/subl.exe'
-w"
• Using Notepad++ as your editor
– Install Notepad++.
– Open Git Bash.
– Type this command:
git config --global core.editor "'C:/Program Files
(x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -
noPlugin"
git init
• Running the git init command sets up all of the necessary files and
directories that Git will use to keep track of everything.
• All of these files are stored in a directory called .git (notice the . at the
beginning - that means it'll be a hidden directory on Mac/Linux).
• This .git directory is the "repo"! This is where git records all of the commits
and keeps track of everything!
Local git areas
git clone
• The git clone command is used to create an identical copy of an existing
repository.
$ git clone <path-to-repository-to-clone>
This command:
 takes the path to an existing repository
 by default will create a directory with the same name as the repository that's being
cloned
 can be given a second argument that will be used as the name of the directory
 will create the new repository inside of the current working directory
git status
• The git status command displays the state of the working directory and the staging
area.
• It lets you see which changes have been staged, which haven’t, and which files
aren’t being tracked by Git.
• Status output does not show you any information regarding the committed project
history.
git log
• The git log command is used to display all of the commits of a repository.
• By default, this command displays:
 the SHA
 the author
 the date
 and the message
git add
The git add command is used to move files from the Working Directory to the Staging Index.
$ git add <file1> <file2> … <fileN>
This command:
• takes a space-separated list of file names
• alternatively, the period . can be used in place of a list of files to tell Git to add the current
directory (and all nested files)
• git rm --cached <file> command can be used to remove a file from staging Index. This
command will not destroy any of your work, it just removes it from the Staging Index.
git commit
The git commit command takes files from the Staging Index and saves them in
the repository.
$ git commit
This command:
• will open the code editor that is specified in your configuration
• (check out the Git configuration step from the first lesson to configure
your editor)
• Inside the code editor:
– a commit message must be supplied
– lines that start with a # are comments and will not be recorded
– save the file after adding a commit message
– close the editor to make the commit
Then, use git log to review the commit you just made!
Commit message
Do
• do keep the message short (less than 60-ish characters)
• do explain what the commit does (not how or why!)
Do not
• do not explain why the changes are made (more on this below)
• do not explain how the changes are made (that's what git log -p is for!)
• do not use the word "and"
• if you have to use "and", your commit message is probably doing too many
changes - break the changes into separate commits
• e.g. "make the background color pink and increase the size of the sidebar"
git log --oneline
• This command shortens the SHA and commit message to just one line
• Q key is pressed to co come out to regular command prompt
git log --stat
 displays the file(s) that have been modified
 displays the number of lines that have been added/removed
 displays a summary line with the total number of modified files and lines
that have been added/removed
git log –p or git log --patch
This command adds the following to the default output:
 displays the files that have been modified
 displays the location of the lines that have been added/removed
 displays the actual changes that have been made
git show
The git show command will show only one commit.
By default, git show displays:
the commit
the author
the date
the commit message
the patch information
git diff
git diff command is used to see changes that have been made but haven't
been committed, yet:
$ git diff
This command displays:
• the files that have been modified
• the location of the lines that have been added/removed
• the actual changes that have been made
git ignore
• Git sees every file in your working copy as one of three things:
– tracked - a file which has been previously staged or committed;
– untracked - a file which has not been staged or committed; or
– ignored - a file which Git has been explicitly told to ignore.
– Ignored files are usually build artifacts and machine generated files
that can be derived from your repository source or should otherwise
not be committed. Some common examples are:
 compiled code, such as .o, .pyc, and .class files
 build output directories, such as /bin, /out, or /target
 files generated at runtime, such as .log, .lock, or .tmp
 hidden system files, such as .DS_Store or Thumbs.db
git tag
• Git has the ability to tag specific points in history as being important.
• Git supports two types of tags: lightweight and annotated.
 A lightweight tag is very much like a branch that doesn’t change — it’s
just a pointer to a specific commit.
git tag v1.0
 Annotated tags are stored as full objects in the Git database. They’re
checksummed; contain the tagger name, email, and date; have a
tagging message; and can be signed and verified with GNU Privacy
Guard (GPG).
git tag -a v1.0 -m “Insert message.“
 To delete tag
git –d v1.0 or git --delete v1.0
git branch
• Branch enables programmer to work in the same project in different
isolated environments.
• When it is required to add a new feature or fix a bug—no matter how big
or how small ,a new branch can be created to encapsulate the changes.
Commands
• git branch list all of the branches in your repository.
• git branch <branch> create a new branch called <branch>. This
does not check out the new branch.
• git branch -d <branch> delete the specified branch. This is a “safe”
operation in that Git prevents you from deleting the branch if it has
unmerged changes.
• git branch -D <branch> force delete the specified branch, even if it has
unmerged changes.
• git branch -m <branch> rename the current branch to <branch>.
• git checkout <branch> checkout to branch called <branch>.
• git checkout –b <branch> create a new branch called <branch> and
checkout simultaneously.
git merge
The git merge command lets you take the independent lines of development
created by git branch and integrate them into a single branch.
git merge <branch>
There are two types of merging:
1. Fast forward merge
2. 3-way merge.
Fast forward merge
• A fast-forward merge can occur when there is a linear path from the
current branch tip to the target branch.
• Before merge:
• After merge:
3-way merge
• A fast-forward merge is not possible if the branches have diverged. When
there is not a linear path to the target branch, Git has no choice but to
combine them via a 3-way merge. 3-way merges use a dedicated commit
to tie together the two histories.
• Before Merge
• After Merge
Merge conflict
• If the two branches you're trying to merge both changed the same part of
the same file, Git won't be able to figure out which version to use. When
such a situation occurs, it stops right before the merge commit so that you
can resolve the conflicts manually.
• visual markers to represent conflict are: <<<<<<<, =======, and >>>>>>>.
--amend
• Git commit –amend command is used to edit most recent commit.
git commit --amend
• Steps involved are:
– edit the file(s)
– save the file(s)
– stage the file(s)
– and run git commit --amend
git revert
The git revert command is used to reverse a previously made commit:
$ git revert <SHA-of-commit-to-revert>
This command:
 will undo the changes that were made by the provided commit
 creates a new commit to record the change
git reset
• git reset --option <SHA> command is used to erase commits. There are
three options to reset.
1. –soft (erased commits shifts to staging index)
2. –mixed(default and (erased commits shifts to working directory)
3. –hard(erases directly)
Remote repositry
• A remote repository is the same Git repository like yours but it exists
somewhere else.
• Remotes can be accessed in a couple of ways:
– with a URL
– path to a file system
• we can interact and control a remote repository is through the Git remote
command:
– $ git remote
git push
• Create a new repository on GitHub. To avoid errors, do not initialize the
new repository with README, license, or .gitignore files. You can add
these files after your project has been pushed to GitHub.
• Open Git Bash.
• Change the current working directory to your local project.
• Initialize the local directory as a Git repository.
– git init
• Add the files in your new local repository. This stages them for the first
commit.
– git add .
• Commit the files that you've staged in your local repository.
– git commit -m "First commit"
• Copy remote repository URL field at the top of your GitHub repository's
Quick Setup page, click to copy the remote repository URL.
• In the Command prompt, add the URL for the remote repository where
your local repository will be pushed.
-git remote add origin remote repository URL
• git remote –v command verifies the new remote URL
• Push the changes in your local repository to GitHub.
-git push origin master
# Pushes the changes in your local repository up to the remote repository you
specified as the origin
git fetch or git pull
• The git fetch command downloads commits, files, and refs from a remote
repository into your local repo. Git isolates fetched content as a from
existing local content, it has absolutely no effect on your local
development work.
– git push origin master
– git fetch origin master
• This makes fetching a safe way to review commits before integrating them
with your local repository.
• git fetch is the 'safe' version of the two commands. It will download the
remote content but not update your local repo's working state, leaving
your current work intact. git pull is the more aggressive alternative, it will
download the remote content for the active local branch and immediately
execute git merge to create a merge commit for the new remote content.
Thank You

Contenu connexe

Tendances

Tendances (20)

Git n git hub
Git n git hubGit n git hub
Git n git hub
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
GIT presentation
GIT presentationGIT presentation
GIT presentation
 
Github basics
Github basicsGithub basics
Github basics
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git
GitGit
Git
 
CI/CD with GitHub Actions
CI/CD with GitHub ActionsCI/CD with GitHub Actions
CI/CD with GitHub Actions
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Introduction to Git and GitHub Part 1
Introduction to Git and GitHub Part 1Introduction to Git and GitHub Part 1
Introduction to Git and GitHub Part 1
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
git and github
git and githubgit and github
git and github
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
GitHub Presentation
GitHub PresentationGitHub Presentation
GitHub Presentation
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 

Similaire à Git hub

Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with Git
Things Lab
 

Similaire à Git hub (20)

git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx
 
Git 101
Git 101Git 101
Git 101
 
GIT.pptx
GIT.pptxGIT.pptx
GIT.pptx
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
 
Git introduction
Git introductionGit introduction
Git introduction
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with Git
 
CSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GITCSE 390 Lecture 9 - Version Control with GIT
CSE 390 Lecture 9 - Version Control with GIT
 
IS - section 1 - modifiedFinal information system.pptx
IS - section 1 - modifiedFinal information system.pptxIS - section 1 - modifiedFinal information system.pptx
IS - section 1 - modifiedFinal information system.pptx
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
Git for developers
Git for developersGit for developers
Git for developers
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptx
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Mini-training: Let’s Git It!
Mini-training: Let’s Git It!Mini-training: Let’s Git It!
Mini-training: Let’s Git It!
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 

Dernier

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Dernier (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Git hub

  • 1.
  • 2. Git - GitHub Presented By: Nitin Goel
  • 3. About Git • Created by Linus Torvalds, creator of Linux, in 2005 – Came out of Linux development community – Designed to do version control on Linux kernel • Goals of Git: – Speed – Support for non-linear development (thousands of parallel branches) – Fully distributed – Able to handle large projects efficiently
  • 4. Centralized VCS • In Subversion, CVS, Perforce, etc. A central server repository (repo) holds the "official copy" of the code • The server maintains the sole version history of the repo • You make "checkouts" of it to your local copy • You make local modifications • Your changes are not versioned • When you're done, you "check in" back to the server • Your check in increments the repo's version
  • 5. Distributed VCS (Git) • In git, mercurial, etc., you don't "checkout" from a central repo, you "clone" it and "pull" changes from it • Your local repo is a complete copy of everything on the remote server • Yours is "just as good" as theirs • Many operations are local: – check in/out from local repo – commit changes to local repo – local repo keeps version history • When you're ready, you can "push" changes back to server
  • 6. Version Control • Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. • Allows for collaborative development • Allows you to know who made what changes and when • Allows you to revert any changes and go back to a previous state • Three of the most popular version control systems are:  Git  Subversion  Mercurial
  • 7. Git vs Github • Git is a revision control system, a tool to manage your source code history. • Github is a hosting service for Git repositories.
  • 8. Terminology Version Control System / Source Code Manager  A version control system (abbreviated as VCS) is a tool that manages different versions of source code. A source code manager (abbreviated as SCM) is another name for a version control system. Commit  Git thinks of its data like a set of snapshots of a mini file system. Every time you commit (save the state of your project in Git), it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. You can think of it as a save point in a game - it saves your project's files and any information about them. Repository / repo  A repository is a directory which contains your project work, as well as a few files (hidden by default on Mac OS X) which are used to communicate with Git. Repositories can exist either locally on your computer or as a remote copy on another computer. A repository is made up of commits.
  • 9. Terminology Working Directory  The Working Directory is the files that you see in your computer's file system. When you open your project files up on a code editor, you're working with files in the Working Directory.  This is in contrast to the files that have been saved (in commits!) in the repository. Checkout  A checkout is when content in the repository has been copied to the Working Directory. Staging Area / Staging Index / Index  A file in the Git directory that stores information about what will go into your next commit. You can think of the staging area as a prep table where Git will take the next commit. Files on the Staging Index are poised to be added to the repository. SHA(Secure Hash Algorithm)  A SHA is basically an ID number for each commit. Here's what a commit's SHA might look like: e2adf8ae3e2e4ed40add75cc44cf9d0a869afeb6. Branch  A branch is when a new line of development is created that diverges from the main line of development. This alternative line of development can continue without altering the main line.
  • 10. Install Git on Windows • Download the latest Git for windows installer. • When you've successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation. • Open a Command Prompt (or Git Bash if during installation you elected not to use Git from the Windows Command Prompt). • Run the following commands to configure your Git. These details will be associated with any commits that you create.
  • 11. Git Configuration • # sets up Git with your name git config --global user.name "<Your-Full-Name>" • # sets up Git with your email git config --global user.email "<your-email-address>" • # makes sure that Git output is colored git config --global color.ui auto • # displays the original state in a conflict git config --global merge.conflictstyle diff3 • git config --list
  • 12. Associating text editors with Git • Using Atom as your editor – Install Atom. – Open Git Bash. – Type this command: git config --global core.editor “C:/Users/USERNAME/AppData/Local/atom/bin/atom.cmd” Using Sublime Text as your editor – Install Sublime Text 3. – Open Git Bash. – Type this command: git config --global core.editor "'c:/program files/sublime text 3/subl.exe' -w"
  • 13. • Using Notepad++ as your editor – Install Notepad++. – Open Git Bash. – Type this command: git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession - noPlugin"
  • 14. git init • Running the git init command sets up all of the necessary files and directories that Git will use to keep track of everything. • All of these files are stored in a directory called .git (notice the . at the beginning - that means it'll be a hidden directory on Mac/Linux). • This .git directory is the "repo"! This is where git records all of the commits and keeps track of everything!
  • 16.
  • 17. git clone • The git clone command is used to create an identical copy of an existing repository. $ git clone <path-to-repository-to-clone> This command:  takes the path to an existing repository  by default will create a directory with the same name as the repository that's being cloned  can be given a second argument that will be used as the name of the directory  will create the new repository inside of the current working directory
  • 18. git status • The git status command displays the state of the working directory and the staging area. • It lets you see which changes have been staged, which haven’t, and which files aren’t being tracked by Git. • Status output does not show you any information regarding the committed project history.
  • 19.
  • 20. git log • The git log command is used to display all of the commits of a repository. • By default, this command displays:  the SHA  the author  the date  and the message
  • 21. git add The git add command is used to move files from the Working Directory to the Staging Index. $ git add <file1> <file2> … <fileN> This command: • takes a space-separated list of file names • alternatively, the period . can be used in place of a list of files to tell Git to add the current directory (and all nested files) • git rm --cached <file> command can be used to remove a file from staging Index. This command will not destroy any of your work, it just removes it from the Staging Index.
  • 22. git commit The git commit command takes files from the Staging Index and saves them in the repository. $ git commit This command: • will open the code editor that is specified in your configuration • (check out the Git configuration step from the first lesson to configure your editor) • Inside the code editor: – a commit message must be supplied – lines that start with a # are comments and will not be recorded – save the file after adding a commit message – close the editor to make the commit Then, use git log to review the commit you just made!
  • 23.
  • 24. Commit message Do • do keep the message short (less than 60-ish characters) • do explain what the commit does (not how or why!) Do not • do not explain why the changes are made (more on this below) • do not explain how the changes are made (that's what git log -p is for!) • do not use the word "and" • if you have to use "and", your commit message is probably doing too many changes - break the changes into separate commits • e.g. "make the background color pink and increase the size of the sidebar"
  • 25. git log --oneline • This command shortens the SHA and commit message to just one line • Q key is pressed to co come out to regular command prompt
  • 26. git log --stat  displays the file(s) that have been modified  displays the number of lines that have been added/removed  displays a summary line with the total number of modified files and lines that have been added/removed
  • 27. git log –p or git log --patch This command adds the following to the default output:  displays the files that have been modified  displays the location of the lines that have been added/removed  displays the actual changes that have been made
  • 28. git show The git show command will show only one commit. By default, git show displays: the commit the author the date the commit message the patch information
  • 29. git diff git diff command is used to see changes that have been made but haven't been committed, yet: $ git diff This command displays: • the files that have been modified • the location of the lines that have been added/removed • the actual changes that have been made
  • 30.
  • 31. git ignore • Git sees every file in your working copy as one of three things: – tracked - a file which has been previously staged or committed; – untracked - a file which has not been staged or committed; or – ignored - a file which Git has been explicitly told to ignore. – Ignored files are usually build artifacts and machine generated files that can be derived from your repository source or should otherwise not be committed. Some common examples are:  compiled code, such as .o, .pyc, and .class files  build output directories, such as /bin, /out, or /target  files generated at runtime, such as .log, .lock, or .tmp  hidden system files, such as .DS_Store or Thumbs.db
  • 32. git tag • Git has the ability to tag specific points in history as being important. • Git supports two types of tags: lightweight and annotated.  A lightweight tag is very much like a branch that doesn’t change — it’s just a pointer to a specific commit. git tag v1.0  Annotated tags are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG). git tag -a v1.0 -m “Insert message.“  To delete tag git –d v1.0 or git --delete v1.0
  • 33. git branch • Branch enables programmer to work in the same project in different isolated environments. • When it is required to add a new feature or fix a bug—no matter how big or how small ,a new branch can be created to encapsulate the changes.
  • 34. Commands • git branch list all of the branches in your repository. • git branch <branch> create a new branch called <branch>. This does not check out the new branch. • git branch -d <branch> delete the specified branch. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes. • git branch -D <branch> force delete the specified branch, even if it has unmerged changes. • git branch -m <branch> rename the current branch to <branch>. • git checkout <branch> checkout to branch called <branch>. • git checkout –b <branch> create a new branch called <branch> and checkout simultaneously.
  • 35. git merge The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. git merge <branch> There are two types of merging: 1. Fast forward merge 2. 3-way merge.
  • 36. Fast forward merge • A fast-forward merge can occur when there is a linear path from the current branch tip to the target branch.
  • 37. • Before merge: • After merge:
  • 38. 3-way merge • A fast-forward merge is not possible if the branches have diverged. When there is not a linear path to the target branch, Git has no choice but to combine them via a 3-way merge. 3-way merges use a dedicated commit to tie together the two histories.
  • 39.
  • 40. • Before Merge • After Merge
  • 41. Merge conflict • If the two branches you're trying to merge both changed the same part of the same file, Git won't be able to figure out which version to use. When such a situation occurs, it stops right before the merge commit so that you can resolve the conflicts manually. • visual markers to represent conflict are: <<<<<<<, =======, and >>>>>>>.
  • 42. --amend • Git commit –amend command is used to edit most recent commit. git commit --amend • Steps involved are: – edit the file(s) – save the file(s) – stage the file(s) – and run git commit --amend
  • 43. git revert The git revert command is used to reverse a previously made commit: $ git revert <SHA-of-commit-to-revert> This command:  will undo the changes that were made by the provided commit  creates a new commit to record the change
  • 44. git reset • git reset --option <SHA> command is used to erase commits. There are three options to reset. 1. –soft (erased commits shifts to staging index) 2. –mixed(default and (erased commits shifts to working directory) 3. –hard(erases directly)
  • 45. Remote repositry • A remote repository is the same Git repository like yours but it exists somewhere else. • Remotes can be accessed in a couple of ways: – with a URL – path to a file system • we can interact and control a remote repository is through the Git remote command: – $ git remote
  • 46. git push • Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or .gitignore files. You can add these files after your project has been pushed to GitHub. • Open Git Bash. • Change the current working directory to your local project. • Initialize the local directory as a Git repository. – git init • Add the files in your new local repository. This stages them for the first commit. – git add . • Commit the files that you've staged in your local repository. – git commit -m "First commit"
  • 47. • Copy remote repository URL field at the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL. • In the Command prompt, add the URL for the remote repository where your local repository will be pushed. -git remote add origin remote repository URL • git remote –v command verifies the new remote URL • Push the changes in your local repository to GitHub. -git push origin master # Pushes the changes in your local repository up to the remote repository you specified as the origin
  • 48. git fetch or git pull • The git fetch command downloads commits, files, and refs from a remote repository into your local repo. Git isolates fetched content as a from existing local content, it has absolutely no effect on your local development work. – git push origin master – git fetch origin master • This makes fetching a safe way to review commits before integrating them with your local repository. • git fetch is the 'safe' version of the two commands. It will download the remote content but not update your local repo's working state, leaving your current work intact. git pull is the more aggressive alternative, it will download the remote content for the active local branch and immediately execute git merge to create a merge commit for the new remote content.