SlideShare a Scribd company logo
>_ Things Lab
Source code management with Git
Source Code Management with Git
What is Git?
• Source Code Management (SCM) system
• Designed for Linux Kernel development
• Free software as “Free Beer”
• Multiplatform
Git is not
• Another version of SVN
• Expensive
• A hacker’s tool to develop Linux kernel
• Hard to set up
• Hard to learn
• Complex
Why Git?
• Strong support for non-lineardevelopment
• Distributed development
• Efficient for large projects
• Faster than other SCM systems
• Very fast and portable (written in C)
Getting Git in RPi
• To install Git in Raspberry Pi image, execute
sudo apt-get install git-core
• Now run
git --version
• This will show the version of Git installed
Configuring Git
• Adding your info:
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git config --global color.ui true
• Git services (like GitHub) will identify you by
using this information
Some simple commands
• Initializinga local repository
git init [path/to/repo]
• Getting a remote repository
git clone https://user@service/path/to/repo.git
Playing with git
mkdir Desktop/learning_git
cd Desktop/learning_git
git init
• This will create a repository in a folder named
learning_git, outputting this
Initialized empty Git repository in
/home/rpi/Desktop/learning_git/.git/
Adding files to repo
• Add some text to a file called “hello.txt”:
nano hello.txt # opens hello.txt in nano editor
• Write something in the file just created and
CTRL+X to exit from the editor (press Y to save
changes in hello.txt)
Adding files to repo
git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be
committed)
#
# hello.txt
nothing added to commit but untracked files present (use
"git add" to track)
Adding files to repo
git add "hello.txt"
• This will add “hello.txt” to your repository,
making it ready for commit
• Now check the status again…
• This process (creating files then adding them)
is called staging
Staging
Adding more files
• Create two other text files called “file1.txt”
and “file2.txt”
• Check the status (git status)
• You can add all files to stage by executing one
of these:
git add *.txt # adds only .txt files
git add . # adds every file
Commits (CTRL+S the project)
Commits (CTRL+S the project)
• Committing is just like saving the current stage
in the history
• Committing helps you return in a previous
stage of the project (in case you screw up
everything)
• Execute:
git commit -m "Initial Commit"
• Now check the status, again
Checking history
• Now create some other files and commit
them.
• After committing again, execute git log to see
all commits, along with the message for each
of them.
Source Code Management with Git
CTRL+Z with git checkout
• Checking out (git checkout) does 3 things:
– Checks out files
git checkout <commit> <file>
– Checks out commits
git checkout <commit>
– Checks out branches
git checkout <branch>
CTRL+Z with git checkout
• To get the ID of every commit:
git log --oneline
• Pick an ID and execute:
git checkout <commit>
• Now check the files on your repo; they are not
the same as before!
CTRL+Z with git checkout
CTRL+Z with git revert
• To get the ID of every commit:
git log --oneline
• Pick an ID and execute:
git revert <commit>
• Reverting does not remove the commit from
the history. Instead, it undoes the changes by
that commit and creates a new commit with
changes undone
CTRL+Z with git revert
CTRL+Z with git reset
• Dangerous version of git reverse
• Permanent undo: git reset is irreversible
• Often used (securely) to undo changes in
staging area and/or working directory (i.e.
delete changes not committed yet)
CTRL+Z with git reset
• Let’s assume there are 3 files in the local repo.
Execute:
git add . # stage all files
git reset file2 # remove file2
git commit -m "testing git reset" # commit changes
# this will remove unstaged files i.e. file2
git clean -f
• Since file2 is removed using git reset, it won’t
commit
Source Code Management with Git
Branches
• Independentworkflowsof development
• Mostly used to fix bugs and/or add features to
a project
Branches
• Useful commands:
git branch # list branches
git branch <branch> # create new branch
git branch -d <branch> # delete <branch>
git branch -D <branch> # force delete <branch>
git branch -m <branch> # rename current branch
Branches
Branches
• Execute:
git branch try_branches # create a new branch
git checkout try_branches # go to that branch
# create some files and commit them
git checkout master # main branch is master
# check files
# no one has changed
# branches are independent
Merge branches
Merge branches
• There are two types of merging:
– Fast Forward Merging
– 3 Way Merging
# this merges <branch> with the current branch
# merging type is decided by Git
git merge <branch>
Fast Forward Merging
Fast Forward Merging
• Make sure you are on master branch, and
execute (after executing code on slide 30):
# this will merge try_branching to master
git merge try_branching
3 Way Merging
3 Way Merging
• Do:
1. Create a new branch (branch3WM)
2. Add a new file to master and commit it
3. Move to branch3WM and add some files and
commit them
4. Move to master branch
5. Do the 3 Way Merging (git merge branch3WM)
3 Way Merging conflicts
• Conflicts happen when
– The same file is modified in 2 different branches
– 2 (or more) developers work on the same project
simultaneously
• TODO for you:
– Simulate (and fix) a 3WM conflict
Remote repos
• Putting your code online makes it simpler for
others to cooperate
• All files, branches and local repo history is
available for others to downloadand have the
same repo as you do
Working with connections
• Useful commands:
git remote # list all remote repos
git remote –v # list with url
git remote add <name> <url> # add a new remote repo
git remote rm <name> # remove a remote repo
git remote rename <old> <new> # rename a repo
Working with connections
• Execute this:
#
# This will add a remote repo named
# thl_lg_repo with
#
git remote add thl_lg_repo
https://bitbucket.org/aziflaj/thl_learning_git.git
Fetching from a remote repo
Fetching from a remote repo
• Useful commands:
git fetch <remote> # fetch all branches
git fetch <remote> <branch> # fetch only a branch
• After fetching, execute git merge to update
your master branch
Pulling from a remote repo
• Pulling = fetching + merging
• Useful commands:
# same as git fetch and then git merge
git pull <remote>
Pulling from a remote repo
Pushing to a remote repo
• Pushing is the opposite of fetching
• Transfers files from local to remote repo
(overwrites changes)
• Useful commands:
git push <remote> <branch> # push a branch only
git push <remote> --all # push all branches
git push <remote> --force # force push
Pushing to a remote repo
Git in a nutshell

More Related Content

What's hot (20)

PDF
Git 101
Dimitris Tsironis
 
PDF
Git tutorial
Elli Kanal
 
PPTX
Git-ing out of your git messes
Katie Sylor-Miller
 
PDF
Git - Get Ready To Use It
Daniel Kummer
 
PPTX
Gitting out of trouble
Jon Senchyna
 
PDF
Git basics
Surabhi Gupta
 
ODP
The Fundamentals of Git
DivineOmega
 
PDF
Git for the absolute beginners
Gabriele Baldassarre
 
KEY
Git Basics at Rails Underground
Ariejan de Vroom
 
PDF
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Ahmed El-Arabawy
 
PDF
Git: basic to advanced
Yodalee
 
PDF
Version Control & Git
Craig Smith
 
PDF
Git Introduction Tutorial
Thomas Rausch
 
PPTX
Git for beginner
Trung Huynh
 
PDF
Git basics with notes
Surabhi Gupta
 
PDF
GIT | Distributed Version Control System
Mohammad Imam Hossain
 
PDF
Git hub
Nitin Goel
 
PPT
Basic Linux day 6
Saikumar Daram
 
Git tutorial
Elli Kanal
 
Git-ing out of your git messes
Katie Sylor-Miller
 
Git - Get Ready To Use It
Daniel Kummer
 
Gitting out of trouble
Jon Senchyna
 
Git basics
Surabhi Gupta
 
The Fundamentals of Git
DivineOmega
 
Git for the absolute beginners
Gabriele Baldassarre
 
Git Basics at Rails Underground
Ariejan de Vroom
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Ahmed El-Arabawy
 
Git: basic to advanced
Yodalee
 
Version Control & Git
Craig Smith
 
Git Introduction Tutorial
Thomas Rausch
 
Git for beginner
Trung Huynh
 
Git basics with notes
Surabhi Gupta
 
GIT | Distributed Version Control System
Mohammad Imam Hossain
 
Git hub
Nitin Goel
 
Basic Linux day 6
Saikumar Daram
 

Viewers also liked (19)

PPTX
SOURCE CODE MANAGEMENT SYSTEM (GITHUB)
Gracy Joseph
 
DOCX
College Management System project
Manish Kushwaha
 
PPTX
Hardik cpd
Patel Hardik
 
DOC
Axlers CV for 2014
DeAnna Axler
 
PPTX
Diapositiva yenis sena 2014
Yenis del Hernandez
 
DOC
anand resume Sep-14
Anandhan Varatharajan
 
PPTX
YOU and ME
UCy Rukmana
 
PDF
Encuestra grupal II
Paulamartinhorcajo
 
PDF
Get started with dropbox
هانى نبيل
 
PDF
Visualizing Built Environments and Injury in Low Resource Settings
Independent Consultant | Research, data, tech policy
 
DOCX
Resume c.v. new updated.
Sofitel Luxury Hotels and Resorts
 
PDF
Wealthcare for Women
Thomas Mastromatto NMLS #145824
 
DOCX
English report
wzhen77
 
PPTX
Dhruvit.ppt
Dhruvit Kukadiya
 
PDF
REGALIA
Sydney S. Budina
 
PPTX
Johannes K.
johannes nikoghossian
 
PPTX
Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...
Ciro Lentano
 
PDF
DHRUVIT RESUME 1.PDF
Dhruvit Kukadiya
 
PDF
Nija_Taylor_SampleBlogWork
Nija Taylor
 
SOURCE CODE MANAGEMENT SYSTEM (GITHUB)
Gracy Joseph
 
College Management System project
Manish Kushwaha
 
Hardik cpd
Patel Hardik
 
Axlers CV for 2014
DeAnna Axler
 
Diapositiva yenis sena 2014
Yenis del Hernandez
 
anand resume Sep-14
Anandhan Varatharajan
 
YOU and ME
UCy Rukmana
 
Encuestra grupal II
Paulamartinhorcajo
 
Get started with dropbox
هانى نبيل
 
Visualizing Built Environments and Injury in Low Resource Settings
Independent Consultant | Research, data, tech policy
 
Resume c.v. new updated.
Sofitel Luxury Hotels and Resorts
 
Wealthcare for Women
Thomas Mastromatto NMLS #145824
 
English report
wzhen77
 
Dhruvit.ppt
Dhruvit Kukadiya
 
Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...
Ciro Lentano
 
DHRUVIT RESUME 1.PDF
Dhruvit Kukadiya
 
Nija_Taylor_SampleBlogWork
Nija Taylor
 
Ad

Similar to Source Code Management with Git (20)

PDF
Git of every day
Alan Descoins
 
PDF
Git and github 101
Senthilkumar Gopal
 
PDF
Git training v10
Skander Hamza
 
PPT
B4usolution git git-hub
b4usolution .
 
PDF
Git tutorial
mobaires
 
PPTX
An introduction to Git
Muhil Vannan
 
PDF
Advanced Git Tutorial
Sage Sharp
 
PPTX
Git 101 - An introduction to Version Control using Git
John Tighe
 
PPTX
Introduction to Git and GitHub
Bioinformatics and Computational Biosciences Branch
 
PPTX
Intro to git and git hub
Venkat Malladi
 
PDF
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
PDF
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
PPTX
Working with Git
Sanghoon Hong
 
PPTX
Git_new.pptx
BruceLee275640
 
PPT
Report about the dangers of git and github on the environment
lameche1islam
 
PPT
Git-GitHub.ppt Diploma in computer. engineering
Roshankumar558219
 
PPT
Distributed Version control using Git and Github
RikinBasu1
 
PPTX
Mastering GIT
Hasnaeen Rahman
 
PDF
Git with the flow
Dana White
 
Git of every day
Alan Descoins
 
Git and github 101
Senthilkumar Gopal
 
Git training v10
Skander Hamza
 
B4usolution git git-hub
b4usolution .
 
Git tutorial
mobaires
 
An introduction to Git
Muhil Vannan
 
Advanced Git Tutorial
Sage Sharp
 
Git 101 - An introduction to Version Control using Git
John Tighe
 
Intro to git and git hub
Venkat Malladi
 
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
Working with Git
Sanghoon Hong
 
Git_new.pptx
BruceLee275640
 
Report about the dangers of git and github on the environment
lameche1islam
 
Git-GitHub.ppt Diploma in computer. engineering
Roshankumar558219
 
Distributed Version control using Git and Github
RikinBasu1
 
Mastering GIT
Hasnaeen Rahman
 
Git with the flow
Dana White
 
Ad

More from Things Lab (14)

PPT
3D Printer Workshop - From your idea to a real object
Things Lab
 
ODP
Things lab - Intro fritzing
Things Lab
 
ODP
Things lab - introduction to programming
Things Lab
 
PDF
Real world Webapp
Things Lab
 
PDF
Rapid Prototyping
Things Lab
 
PPT
Website with HTML CSS
Things Lab
 
PDF
(Not so) big data with Chart.js
Things Lab
 
PDF
Arduino
Things Lab
 
PDF
Cryptanalysis - basic ciphers and a bit more
Things Lab
 
PDF
PHP and Databases
Things Lab
 
PDF
PHP Programming: Intro
Things Lab
 
PDF
Some hours of python
Things Lab
 
PPTX
An Hour of Arduino and Ardublock
Things Lab
 
PDF
Databases and MySQL
Things Lab
 
3D Printer Workshop - From your idea to a real object
Things Lab
 
Things lab - Intro fritzing
Things Lab
 
Things lab - introduction to programming
Things Lab
 
Real world Webapp
Things Lab
 
Rapid Prototyping
Things Lab
 
Website with HTML CSS
Things Lab
 
(Not so) big data with Chart.js
Things Lab
 
Arduino
Things Lab
 
Cryptanalysis - basic ciphers and a bit more
Things Lab
 
PHP and Databases
Things Lab
 
PHP Programming: Intro
Things Lab
 
Some hours of python
Things Lab
 
An Hour of Arduino and Ardublock
Things Lab
 
Databases and MySQL
Things Lab
 

Recently uploaded (20)

PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Human Resources Information System (HRIS)
Amity University, Patna
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
Import Data Form Excel to Tally Services
Tally xperts
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 

Source Code Management with Git

  • 1. >_ Things Lab Source code management with Git
  • 3. What is Git? • Source Code Management (SCM) system • Designed for Linux Kernel development • Free software as “Free Beer” • Multiplatform
  • 4. Git is not • Another version of SVN • Expensive • A hacker’s tool to develop Linux kernel • Hard to set up • Hard to learn • Complex
  • 5. Why Git? • Strong support for non-lineardevelopment • Distributed development • Efficient for large projects • Faster than other SCM systems • Very fast and portable (written in C)
  • 6. Getting Git in RPi • To install Git in Raspberry Pi image, execute sudo apt-get install git-core • Now run git --version • This will show the version of Git installed
  • 7. Configuring Git • Adding your info: git config --global user.name "John Doe" git config --global user.email [email protected] git config --global color.ui true • Git services (like GitHub) will identify you by using this information
  • 8. Some simple commands • Initializinga local repository git init [path/to/repo] • Getting a remote repository git clone https://user@service/path/to/repo.git
  • 9. Playing with git mkdir Desktop/learning_git cd Desktop/learning_git git init • This will create a repository in a folder named learning_git, outputting this Initialized empty Git repository in /home/rpi/Desktop/learning_git/.git/
  • 10. Adding files to repo • Add some text to a file called “hello.txt”: nano hello.txt # opens hello.txt in nano editor • Write something in the file just created and CTRL+X to exit from the editor (press Y to save changes in hello.txt)
  • 11. Adding files to repo git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # hello.txt nothing added to commit but untracked files present (use "git add" to track)
  • 12. Adding files to repo git add "hello.txt" • This will add “hello.txt” to your repository, making it ready for commit • Now check the status again… • This process (creating files then adding them) is called staging
  • 14. Adding more files • Create two other text files called “file1.txt” and “file2.txt” • Check the status (git status) • You can add all files to stage by executing one of these: git add *.txt # adds only .txt files git add . # adds every file
  • 16. Commits (CTRL+S the project) • Committing is just like saving the current stage in the history • Committing helps you return in a previous stage of the project (in case you screw up everything) • Execute: git commit -m "Initial Commit" • Now check the status, again
  • 17. Checking history • Now create some other files and commit them. • After committing again, execute git log to see all commits, along with the message for each of them.
  • 19. CTRL+Z with git checkout • Checking out (git checkout) does 3 things: – Checks out files git checkout <commit> <file> – Checks out commits git checkout <commit> – Checks out branches git checkout <branch>
  • 20. CTRL+Z with git checkout • To get the ID of every commit: git log --oneline • Pick an ID and execute: git checkout <commit> • Now check the files on your repo; they are not the same as before!
  • 21. CTRL+Z with git checkout
  • 22. CTRL+Z with git revert • To get the ID of every commit: git log --oneline • Pick an ID and execute: git revert <commit> • Reverting does not remove the commit from the history. Instead, it undoes the changes by that commit and creates a new commit with changes undone
  • 23. CTRL+Z with git revert
  • 24. CTRL+Z with git reset • Dangerous version of git reverse • Permanent undo: git reset is irreversible • Often used (securely) to undo changes in staging area and/or working directory (i.e. delete changes not committed yet)
  • 25. CTRL+Z with git reset • Let’s assume there are 3 files in the local repo. Execute: git add . # stage all files git reset file2 # remove file2 git commit -m "testing git reset" # commit changes # this will remove unstaged files i.e. file2 git clean -f • Since file2 is removed using git reset, it won’t commit
  • 27. Branches • Independentworkflowsof development • Mostly used to fix bugs and/or add features to a project
  • 28. Branches • Useful commands: git branch # list branches git branch <branch> # create new branch git branch -d <branch> # delete <branch> git branch -D <branch> # force delete <branch> git branch -m <branch> # rename current branch
  • 30. Branches • Execute: git branch try_branches # create a new branch git checkout try_branches # go to that branch # create some files and commit them git checkout master # main branch is master # check files # no one has changed # branches are independent
  • 32. Merge branches • There are two types of merging: – Fast Forward Merging – 3 Way Merging # this merges <branch> with the current branch # merging type is decided by Git git merge <branch>
  • 34. Fast Forward Merging • Make sure you are on master branch, and execute (after executing code on slide 30): # this will merge try_branching to master git merge try_branching
  • 36. 3 Way Merging • Do: 1. Create a new branch (branch3WM) 2. Add a new file to master and commit it 3. Move to branch3WM and add some files and commit them 4. Move to master branch 5. Do the 3 Way Merging (git merge branch3WM)
  • 37. 3 Way Merging conflicts • Conflicts happen when – The same file is modified in 2 different branches – 2 (or more) developers work on the same project simultaneously • TODO for you: – Simulate (and fix) a 3WM conflict
  • 38. Remote repos • Putting your code online makes it simpler for others to cooperate • All files, branches and local repo history is available for others to downloadand have the same repo as you do
  • 39. Working with connections • Useful commands: git remote # list all remote repos git remote –v # list with url git remote add <name> <url> # add a new remote repo git remote rm <name> # remove a remote repo git remote rename <old> <new> # rename a repo
  • 40. Working with connections • Execute this: # # This will add a remote repo named # thl_lg_repo with # git remote add thl_lg_repo https://bitbucket.org/aziflaj/thl_learning_git.git
  • 41. Fetching from a remote repo
  • 42. Fetching from a remote repo • Useful commands: git fetch <remote> # fetch all branches git fetch <remote> <branch> # fetch only a branch • After fetching, execute git merge to update your master branch
  • 43. Pulling from a remote repo • Pulling = fetching + merging • Useful commands: # same as git fetch and then git merge git pull <remote>
  • 44. Pulling from a remote repo
  • 45. Pushing to a remote repo • Pushing is the opposite of fetching • Transfers files from local to remote repo (overwrites changes) • Useful commands: git push <remote> <branch> # push a branch only git push <remote> --all # push all branches git push <remote> --force # force push
  • 46. Pushing to a remote repo
  • 47. Git in a nutshell