Lecture1 Git JM
Lecture1 Git JM
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
master
C0
A Git
Sample
2. John and Peter clone the git repository
C0 C0 C0
A Git
Sample
3. John does a commit
C0 C0
C1
C0
A Git
Sample
4. John does a push
C1 C1 C0
C0 C0
A Git
Sample
5. Peter does a pull
C1 C1 C1
C0 C0 C0
A Git
Sample
6. John does a commit & push
C2 C2 C1
C1 C0 C0
C0 C0
A Git
Sample
7. Peter does a commit
C2 C2 C3
C1 C1 C1
C0 C0 C0
A Git
Sample
8. Peter does a pull (fetch & merge)
C2 C2 C4
C1 C1 C2 C3
C0 C0 C1
C0
A Git
Sample
9. Peter does a push
C2 C4 C4
C1 C2 C3 C2 C3
C0 C1 C1
C0 C0
A Git
Sample
10. John does a pull
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)
– 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 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
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
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
Commit Comment on
Pull request Close Pull request
Compare