SlideShare a Scribd company logo
1 of 47
Download to read offline
>_ Things Lab
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.
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
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

What's hot (20)

Git 101
Git 101Git 101
Git 101
 
Git
GitGit
Git
 
Git
GitGit
Git
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
 
Git basics
Git basicsGit basics
Git basics
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Git for beginner
Git for beginnerGit for beginner
Git for beginner
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notes
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 
Git hub
Git hubGit hub
Git hub
 
Basic Linux day 6
Basic Linux day 6Basic Linux day 6
Basic Linux day 6
 

Viewers also liked

Axlers CV for 2014
Axlers  CV for 2014Axlers  CV for 2014
Axlers CV for 2014
DeAnna Axler
 
Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...
Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...
Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...
Ciro Lentano
 
Nija_Taylor_SampleBlogWork
Nija_Taylor_SampleBlogWorkNija_Taylor_SampleBlogWork
Nija_Taylor_SampleBlogWork
Nija Taylor
 

Viewers also liked (19)

SOURCE CODE MANAGEMENT SYSTEM (GITHUB)
SOURCE CODE MANAGEMENT SYSTEM (GITHUB)SOURCE CODE MANAGEMENT SYSTEM (GITHUB)
SOURCE CODE MANAGEMENT SYSTEM (GITHUB)
 
College Management System project
College Management System projectCollege Management System project
College Management System project
 
Hardik cpd
Hardik cpdHardik cpd
Hardik cpd
 
Axlers CV for 2014
Axlers  CV for 2014Axlers  CV for 2014
Axlers CV for 2014
 
Diapositiva yenis sena 2014
Diapositiva yenis sena 2014Diapositiva yenis sena 2014
Diapositiva yenis sena 2014
 
anand resume Sep-14
anand resume Sep-14anand resume Sep-14
anand resume Sep-14
 
YOU and ME
YOU and MEYOU and ME
YOU and ME
 
Encuestra grupal II
Encuestra grupal IIEncuestra grupal II
Encuestra grupal II
 
Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropbox
 
Visualizing Built Environments and Injury in Low Resource Settings
Visualizing Built Environments and Injury in Low Resource SettingsVisualizing Built Environments and Injury in Low Resource Settings
Visualizing Built Environments and Injury in Low Resource Settings
 
Resume c.v. new updated.
Resume c.v. new updated.Resume c.v. new updated.
Resume c.v. new updated.
 
Wealthcare for Women
Wealthcare for WomenWealthcare for Women
Wealthcare for Women
 
English report
English reportEnglish report
English report
 
Dhruvit.ppt
Dhruvit.pptDhruvit.ppt
Dhruvit.ppt
 
REGALIA
REGALIAREGALIA
REGALIA
 
Johannes K.
Johannes K.Johannes K.
Johannes K.
 
Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...
Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...
Infermiere di Famiglia e Comunità: ruolo, competenze, qualità e prospettive n...
 
DHRUVIT RESUME 1.PDF
DHRUVIT RESUME 1.PDFDHRUVIT RESUME 1.PDF
DHRUVIT RESUME 1.PDF
 
Nija_Taylor_SampleBlogWork
Nija_Taylor_SampleBlogWorkNija_Taylor_SampleBlogWork
Nija_Taylor_SampleBlogWork
 

Similar to Source Code Management with Git

Similar to Source Code Management with Git (20)

Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Learning git
Learning gitLearning git
Learning git
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git introduction
Git introductionGit introduction
Git introduction
 
11 git version control
11 git version control11 git version control
11 git version control
 
Luis atencio on_git
Luis atencio on_gitLuis atencio on_git
Luis atencio on_git
 
git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
 
GIT.pptx
GIT.pptxGIT.pptx
GIT.pptx
 
Git github
Git githubGit github
Git github
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 

More from Things Lab

More from Things Lab (14)

3D Printer Workshop - From your idea to a real object
3D Printer Workshop - From your idea to a real object3D Printer Workshop - From your idea to a real object
3D Printer Workshop - From your idea to a real object
 
Things lab - Intro fritzing
Things lab - Intro fritzingThings lab - Intro fritzing
Things lab - Intro fritzing
 
Things lab - introduction to programming
Things lab - introduction to programmingThings lab - introduction to programming
Things lab - introduction to programming
 
Real world Webapp
Real world WebappReal world Webapp
Real world Webapp
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
 
Website with HTML CSS
Website with HTML CSSWebsite with HTML CSS
Website with HTML CSS
 
(Not so) big data with Chart.js
(Not so) big data with Chart.js(Not so) big data with Chart.js
(Not so) big data with Chart.js
 
Arduino
ArduinoArduino
Arduino
 
Cryptanalysis - basic ciphers and a bit more
Cryptanalysis - basic ciphers and a bit moreCryptanalysis - basic ciphers and a bit more
Cryptanalysis - basic ciphers and a bit more
 
PHP and Databases
PHP and DatabasesPHP and Databases
PHP and Databases
 
PHP Programming: Intro
PHP Programming: IntroPHP Programming: Intro
PHP Programming: Intro
 
Some hours of python
Some hours of pythonSome hours of python
Some hours of python
 
An Hour of Arduino and Ardublock
An Hour of Arduino and ArdublockAn Hour of Arduino and Ardublock
An Hour of Arduino and Ardublock
 
Databases and MySQL
Databases and MySQLDatabases and MySQL
Databases and MySQL
 

Recently uploaded

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 

Source Code Management with Git

  • 1. >_ Things Lab Source code management with Git
  • 2.
  • 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 johndoe@example.com 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.
  • 18.
  • 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
  • 26.
  • 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