0% found this document useful (0 votes)
18 views36 pages

Lecture1 Git JM

Uploaded by

itsashking2712
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views36 pages

Lecture1 Git JM

Uploaded by

itsashking2712
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Git for Version

Control
(Git)
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 checkin 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


Git snapshots
• Centralized VCS like Subversion Subversion
track version data on each
individual file.

• Git keeps "snapshots" of the


entire state of the project.
– Each checkin version of the
Git
overall code has a copy of
each file in it.
– Some files change on a given
checkin, some do not.
– More redundancy, but faster.
A Git
Sample
1. A new git is initialized as a remote
repository
John Remote repository Peter

master

C0
A Git
Sample
2. John and Peter clone the git repository

John Remote repository Peter

master master master

C0 C0 C0
A Git
Sample
3. John does a commit

John Remote repository Peter

master master master

C0 C0
C1

C0
A Git
Sample
4. John does a push

John Remote repository Peter

master master master

C1 C1 C0

C0 C0
A Git
Sample
5. Peter does a pull

John Remote repository Peter

master master master

C1 C1 C1

C0 C0 C0
A Git
Sample
6. John does a commit & push

John Remote repository Peter

master master master

C2 C2 C1

C1 C0 C0

C0 C0
A Git
Sample
7. Peter does a commit

John Remote repository Peter

master master master

C2 C2 C3

C1 C1 C1

C0 C0 C0
A Git
Sample
8. Peter does a pull (fetch & merge)

John Remote repository Peter

master master master

C2 C2 C4

C1 C1 C2 C3

C0 C0 C1

C0
A Git
Sample
9. Peter does a push

John Remote repository Peter

master master master

C2 C4 C4

C1 C2 C3 C2 C3

C0 C1 C1

C0 C0
A Git
Sample
10. John does a pull

John Remote repository Peter

master master master

C4 C4 C4

C2 C3 C2 C3 C2 C3

C1 C1 C1

C0 C0 C0
Local git
areas
• In your local copy on git,
files can be:
– In your local repo
• (committed)

– Checked out and modified,


but not yet committed
• (working copy)

– Or, in-between, in
a "staging" Unmodified/modified Staged Committed
area Files Files Files
• Staged files are ready
• Atocommit
be committed.
saves a snapshot of all staged state.
Basic Git
workflow
• Modify files in your working directory.
• Stage files, adding snapshots of them to your staging area.
• Commit, which takes the files in the staging area and stores
that snapshot permanently to your Git directory.
Initial Git configuration
• Set the name and email for Git to use when you commit:
– git config --global user.name ""
– git config --global user.email @gmail.com
Creating a Git
repo
Two common scenarios: (only do one of these)
• To create a new local Git repo in your current directory:
– git init
• This will create a .git directory in your current directory.
• Then you can commit files in that directory into the repo.
– git add filename
– git commit –m "commit message"

• To clone a remote repo to your current directory:


– git clone url localDirectoryName
• This will create the given local directory, containing a working copy of
the files from the repo, and a .git directory (used to hold the
staging area and your actual local repo)
Git commands
command description
git clone url [dir] copy a Git repository so you can add to it
git add file adds file contents to the staging area
git commit records a snapshot of the staging area
git status view the status of your files in the
working directory and staging area
git diff shows diff of what is staged and what
is modified but unstaged
git help [command] get help info about a particular command

git pull fetch from a remote repo and try to merge


into the current branch
git push push your new branches and data to a
remote repository
others: init, reset, branch, checkout, merge, log, tag
Add and commita
file
• The first time we ask a file to be tracked, and every time
before we commit a file, we must add it to the staging
area:
– git add Hello.java Goodbye.java
• Takes a snapshot of these files, adds them to the staging area.

• To move staged changes into the repo, we commit:


– git commit –m "Fixing bug #22"

• To undo changes on a file before you have committed it:


– git reset HEAD -- filename (unstages the file)
– git checkout -- filename (undoes your changes)
– All these commands are acting on your local version of repo.
Viewing/undoing
changes
• To view status of files in working directory and staging area:
– git status or
– To see what is modified but unstaged:
– git diff

• To see a log of all changes in your local repo:


– git log or git log --oneline (shorter version)
1677b2d Edited first line of readme
258efa7 Added line to readme
0e52da7 Initial commit
• git log -5 (to show only the 5 most recent updates), etc.
Branching and merging
Git uses branching heavily to switch between multiple tasks.

• To create a new local branch:


– git branch name

• To list all local branches: (* = current branch)


– git branch

• To switch to a given local branch:


– git checkout branchname

• To merge changes from a branch into the local master:


– git checkout master
– git merge branchname
Interaction w/ remote
repo
• Push your local changes to the remote repo.
• Pull from remote repo to get most recent changes.
– (fix conflicts if necessary, add/commit them to your local repo)

• To fetch the most recent updates from the remote repo into
your local repo, and put them into your working directory:
– git pull origin master

• To put your changes from your local repo in the remote repo:
– git push origin master
What is Git & Github ?
Git is an example of version control

Version control is a system that records changes to a file or set of files and
helps us recall specific versions later if needed. E.g. Subversion (SVN), CVS etc
It allows you to :
• Revert files or the whole project to an earlier state
• Compare changes over time
• See who modified what?
• Control modifications by collaborators with the permission of admin/owners

•it is a version control tool that will allow you to perform all kinds of operations
to fetch data from the central server or push data to it whereas GitHub is a core
hosting platform for version control collaboration. GitHub is a company that
allows you to host a central repository in a remote server.
Github
Structure
Personal user account Organization account

PUBLIC PRIVATE REMOTE PUBLIC PRIVATE

REPOSITORY
• Unlimited public repositories • Organizations are great for
and collaborators on all that need multiple owners &
plans admins.
• Limited Private repositories • Limited private repositories
• Ability to add unlimited (> Personal)
repository collaborators • Team-based access
• Public repositories are open permissions
to view and copy but not • Unlimited owners, admins, &
commit changes. collaborators using teams
SYNC

CLONE TO GET LOCAL REPOSITORY


Important Concepts for Github
Users
Creating a repo
Creating a repository for multiple people to work together

Master in a repository
This is the final version that is considered ready to use by anybody in the team or outside if
repository is public.

Creating a Branch
• Create a branch in your project, for an environment where you can try out new ideas.
• Changes you make on a branch don't affect the master unless pull request is accepted.
• Changes committed to branch reflects for you to keep track of different versions

Adding Commits
• Keeps track of your progress as you work on a branch or master.
• Creates a transparent history that others can follow to understand what you've done
and why.

Forking a repository
• It creates a copy for you to work on independently without any changes to theirs.
• Submit a pull request to owner so that the owner can incorporate changes.
Concepts for Github
Users ..
Pull requests
• Pull Requests initiates discussion about your commits or changes made to a code.
• See exactly what changes would be merged if pull request is accepted.
• Use GitHub's @mention system in your Pull Request message to ask for feedback from
specific people or teams, or for someone to review your work

Issues
• Highlight bugs or issues with codes that need rectification.
• Issues remain open unless resolved.
• Can be filtered, Can be labeled as bug/enancement/ question/help wanted etc
• @mention can be used to notify someone

Markdown syntax
• Markdown is a way to style text on the web.
• Available in descriptions and comments of Issues and Pull Requests. These include
@mentions as well as references to SHA-1 hashes, Issues, and Pull Requests

Watch and Star


Watch notifies us of all conversations over and above your @mentions, commits,
comments on discussion. Star will favorite it but not show on your dashboards like watch
Understanding Github
Workflow

*Deploying the code is


for development projects

Commit Comment on
Pull request Close Pull request
Compare

Sync or Push to branch Add Issues/ Resolve Issues


Mention Individuals
Github Desktop Demo
Link to download Github Desktop : https://desktop.github.com/
you want to use some code which is present in a public
repository, you can directly copy the contents by cloning or
downloading.

You might also like