SlideShare uma empresa Scribd logo
1 de 44
Baixar para ler offline
git 101: Force sensitive to Jedi Padawan
What is git?
What is ‘git’?
● Distributed Version Control System
● Git is version control for files & directories
● Runs on the command line / terminal
● Stores file versioning information
in a hidden folder at the root of the project
● Version information exists as (relatively lightweight)
difference information between files and file versions
Version Control
● Parallel versions
● Historical versions
Command Line
● Installed system-wide
● Runs on the command line
● Uses SSH Keys (with optional passwords)
● You can also use a GUI for the complex stuff
Everything exists locally
● Without the .git directory, it can’t work
● Everyone has a complete* copy of
the branches and history of the project
● Git is self-sufficient - no remote services needed for
branching or commits
Pushing & Remotes
● Unless you push your code to a remote repository,
it won’t leave your machine
● You can make peer-to-peer pushes
● It’s best to manage sharing and reduce conflicts
by pushing to a single designated remote location
● Pushing puts all of the historical and branching
information into the remote repo
Merges & Conflicts
● Most of the time, git can auto-merge two (or more)
changesets, because they don’t overlap
● Conflicts occur when the file data changes overlap
What does git give you?
● Complete version history
● Easy visualisation of changes
● Ability to work with multiple developers
and effortlessly merge changes
● Parallel versions of source code
● Ability to switch versions or roll back changes
Are you ready to begin?
Core git commands
● commit
● push
● pull
● branch
● checkout
● merge
➔ Save a change
➔ Send changes to a remote
➔ Get changes from a remote
➔ Create a new branch
➔ Switch to a branch or historical version
➔ Combine branches
Getting set up
Setting up a new git repository
Existing repository:
cd /path/to/my/repo
git remote add origin ssh://git@bitbucket.org/username/bbreponame.git
git push -u origin --all
New repository:
mkdir /path/to/your/project
cd /path/to/your/project
git init
git remote add origin ssh://git@bitbucket.org/username/bbreponame.git
Saving changes
Simple git workflow
1. Make your change(s)
2. Test it, make sure it works, and then:
git commit -am “my commit message”
git push origin master
git commit -am “my commit message”
git push origin master
If you don’t use -am, git will open VIM, and you
don’t want that.
your remote location name, the one you gave
it when you set up the repository,
which is usually ‘origin’
the remote branch name,
usually the name of your current
branch
Writing Good commit messages
A good commit message is one that:
● Has a short (<50 character) description
● Uses the imperative, present tense:
“change” not “changed” nor “changes”
● Includes motivation for the change and contrasts with
previous behavior
Making Good commits
● A commit message becomes your
only referral point in the projects’ history
● Your commit must represent a stable point
in your source code history - no half-baked commits!
● Only include relevant files and changes
● Treat every commit as if it were the final release
The GUI is your secret weapon
● A GUI (like Sourcetree) gives an
excellent overview of your
repository
● It makes it possible to craft your
commits on a line-by-line basis
● You can also modify your most
recent commit (so long as you
haven’t pushed it)
Synchronizing
with other repositories
your remote location name, the one you gave
it when you set up the repository,
which is usually ‘origin’
the remote branch name,
usually the name of your current
branch
git commit -am “my commit message”
git pull
git push origin master
if you don’t pull changes and
merge locally before pushing,
your push will likely be rejected
Pulling and Merging
● git fetch will retrieve version information from a remote,
but does nothing with it
● If your push is rejected, it’s likely because the remote is
more up-to-date than your local branch, and you need to
git pull those changes
● Pulling changes will automatically merge them if able;
but if it can’t, you’ll get conflicts that will need to be
resolved manually
Dealing with Conflict
Dealing with conflicts
● A conflict occurs when two changesets are trying to modify
the same lines of code
● Resolving conflicts involves manually picking which of the
two competing modifications are accepted
● Resolving a conflict doesn’t necessarily mean that the code
will still work - you’re going to have to figure that bit out
yourself and edit the file manually
Resolving conflicts is either:
● A yes/no selection between competing
versions of a line of code
● Or manually editing the partial
merge result to resolve the conflicts
You’re going to need a GUI
Avoiding Conflict
● Conflicts occur when you have an overlap, so don’t
reformat, move or refactor code when there’s a chance
someone else has also modified it
● Commit little and often
● Keep your branches up-to-date: Pull changes frequently
● Sort out your crlf settings before you start
● Some conflicts can’t be avoided
Branching
Understanding Branches
Branches:
● Are alternate versions of the working copy of your entire
project, with their own history
● Can be created from, and merged back into other branches
● Can be created explicitly, or implicitly when merging two
versions of the ‘same’ branch
● Allow you to work on features in isolation
Branching strategy
● master is the stable release
● development is for work in progress
● Individual features should have their own branch
● features are branched from development
● Completed features are merged in from development
● Stable development versions are merged in from master
Branching strategy in practice
git checkout -b development // create and switch to development
git checkout -b feature-one // create and switch to feature-one
git commit -am “my awful commit message” // create a commit on feature-one
git checkout development // switch back to development
git merge feature-one // merge feature-one into development
git checkout master // switch to master
git merge development // merge development into master
git push // push master branch to remote
git push -u origin development // push the development branch and set its
‘upstream’
Remote branches
● Unless you explicitly push a branch, or set an upstream for
the branch, it won’t get pushed to the remote repository
Useful tricks
Don’t use fast-forward merges
● The default behaviour of
a merge is to ‘fast
forward’ the original
when possible
● Fast-forwarding
branches doesn’t add an
extra commit for the
merge, which is cleaner
but loses some context
Stashing
● A ‘stash’ is a representation of the differences between your
last commit, and your current working copy.
● In order to switch branches, your current working copy
must not conflict with the branch you’re checking out.
● Been working on the wrong branch?
Stash changes. Checkout the correct branch. Apply stash.
● Got half-finished code but now you’ve got to drop
everything to fix a bug? Stash it. Come back later.
Git Reset
● So long as you haven’t pushed your change to a remote
repository, everything is changeable
● git reset will make it completely forget your commits
● It’s useful if you’ve made changes to the wrong branch
● It can be dangerous
Cherry Picking
● Merging branches brings across the entire history of both
branches and mashes them together.
● A ‘cherry pick’ takes just the changes from a single commit
and can apply them to another branch
● It’s useful, but treat it as an indication that you’ve done
something wrong if you need to use it.
Golden Rules
Golden Rules
● Commit early, commit often (when it’s stable)
● Commit only one feature and its relevant changes at a time
● Write good commit messages
● Develop on feature branches
● Merge feature branches into development,
not the other way around
● Push your changes on a regular basis
Remember
● Git is your time machine
● Git is your safety net
That’s all folks
Bonus
git push --force

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Davinci git brown_bag
Davinci git brown_bagDavinci git brown_bag
Davinci git brown_bag
 
6 git
6 git6 git
6 git
 
Git for folk who like GUIs
Git for folk who like GUIsGit for folk who like GUIs
Git for folk who like GUIs
 
Learning Git
Learning GitLearning Git
Learning Git
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git Migration
 
Intro to Gitflow
Intro to GitflowIntro to Gitflow
Intro to Gitflow
 
Git & GitHub N00bs
Git & GitHub N00bsGit & GitHub N00bs
Git & GitHub N00bs
 
Fundamentals of Git
Fundamentals of GitFundamentals of Git
Fundamentals of Git
 
Git basic
Git basicGit basic
Git basic
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
 
Using Git and BitBucket
Using Git and BitBucketUsing Git and BitBucket
Using Git and BitBucket
 
Git with bitbucket
Git with bitbucketGit with bitbucket
Git with bitbucket
 
Bitbucket
BitbucketBitbucket
Bitbucket
 
GIT INTRODUCTION
GIT INTRODUCTIONGIT INTRODUCTION
GIT INTRODUCTION
 
Git with bitbucket
Git with bitbucketGit with bitbucket
Git with bitbucket
 
Learn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levelsLearn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levels
 
BitBucket presentation
BitBucket presentationBitBucket presentation
BitBucket presentation
 

Semelhante a Git 101: Force-sensitive to Jedi padawan

Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow Sebin Benjamin
 
Version control and GIT Primer
Version control and GIT PrimerVersion control and GIT Primer
Version control and GIT Primersaadulde
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practiceMajid Hosseini
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
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)Ahmed El-Arabawy
 
Introduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
Introduction to Git and Github - Google Developer Student Clubs CET, TrivandrumIntroduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
Introduction to Git and Github - Google Developer Student Clubs CET, TrivandrumAbhijitNarayan2
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced gitGerrit Wanderer
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperJohn Stevenson
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitRobert Lee-Cann
 

Semelhante a Git 101: Force-sensitive to Jedi padawan (20)

Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
 
Github
GithubGithub
Github
 
Version control and GIT Primer
Version control and GIT PrimerVersion control and GIT Primer
Version control and GIT Primer
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
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)
 
Gn unify git
Gn unify gitGn unify git
Gn unify git
 
Introduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
Introduction to Git and Github - Google Developer Student Clubs CET, TrivandrumIntroduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
Introduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
 
Git tips
Git tipsGit tips
Git tips
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
 
Formation git
Formation gitFormation git
Formation git
 
Git Basics
Git BasicsGit Basics
Git Basics
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
 
Lets git to it
Lets git to itLets git to it
Lets git to it
 
Mastering GIT
Mastering GITMastering GIT
Mastering GIT
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
git Technologies
git Technologiesgit Technologies
git Technologies
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern Developer
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Git
GitGit
Git
 

Mais de James Ford

Virtualisation - Vagrant and Docker
Virtualisation - Vagrant and DockerVirtualisation - Vagrant and Docker
Virtualisation - Vagrant and DockerJames Ford
 
The Magic of Charts
The Magic of ChartsThe Magic of Charts
The Magic of ChartsJames Ford
 
Telling Tales and Solving Crimes with New Relic
Telling Tales and Solving Crimes with New RelicTelling Tales and Solving Crimes with New Relic
Telling Tales and Solving Crimes with New RelicJames Ford
 
Responsive images in 10 minutes
Responsive images in 10 minutesResponsive images in 10 minutes
Responsive images in 10 minutesJames Ford
 
'Hack to the future' - Hackathons at MMT Digital
'Hack to the future' - Hackathons at MMT Digital'Hack to the future' - Hackathons at MMT Digital
'Hack to the future' - Hackathons at MMT DigitalJames Ford
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deckJames Ford
 
What the HTML? - The Holy Grail
What the HTML? - The Holy GrailWhat the HTML? - The Holy Grail
What the HTML? - The Holy GrailJames Ford
 
Agile Partners
Agile PartnersAgile Partners
Agile PartnersJames Ford
 
The Flash Facebook Cookbook - FlashMidlands
The Flash Facebook Cookbook - FlashMidlandsThe Flash Facebook Cookbook - FlashMidlands
The Flash Facebook Cookbook - FlashMidlandsJames Ford
 

Mais de James Ford (13)

Virtualisation - Vagrant and Docker
Virtualisation - Vagrant and DockerVirtualisation - Vagrant and Docker
Virtualisation - Vagrant and Docker
 
The Magic of Charts
The Magic of ChartsThe Magic of Charts
The Magic of Charts
 
Telling Tales and Solving Crimes with New Relic
Telling Tales and Solving Crimes with New RelicTelling Tales and Solving Crimes with New Relic
Telling Tales and Solving Crimes with New Relic
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
Web fonts FTW
Web fonts FTWWeb fonts FTW
Web fonts FTW
 
Responsive images in 10 minutes
Responsive images in 10 minutesResponsive images in 10 minutes
Responsive images in 10 minutes
 
'Hack to the future' - Hackathons at MMT Digital
'Hack to the future' - Hackathons at MMT Digital'Hack to the future' - Hackathons at MMT Digital
'Hack to the future' - Hackathons at MMT Digital
 
Fork me!
Fork me!Fork me!
Fork me!
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deck
 
What the HTML? - The Holy Grail
What the HTML? - The Holy GrailWhat the HTML? - The Holy Grail
What the HTML? - The Holy Grail
 
Testacular
TestacularTestacular
Testacular
 
Agile Partners
Agile PartnersAgile Partners
Agile Partners
 
The Flash Facebook Cookbook - FlashMidlands
The Flash Facebook Cookbook - FlashMidlandsThe Flash Facebook Cookbook - FlashMidlands
The Flash Facebook Cookbook - FlashMidlands
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Git 101: Force-sensitive to Jedi padawan

  • 1. git 101: Force sensitive to Jedi Padawan
  • 2.
  • 4. What is ‘git’? ● Distributed Version Control System ● Git is version control for files & directories ● Runs on the command line / terminal ● Stores file versioning information in a hidden folder at the root of the project ● Version information exists as (relatively lightweight) difference information between files and file versions
  • 5. Version Control ● Parallel versions ● Historical versions
  • 6. Command Line ● Installed system-wide ● Runs on the command line ● Uses SSH Keys (with optional passwords) ● You can also use a GUI for the complex stuff
  • 7. Everything exists locally ● Without the .git directory, it can’t work ● Everyone has a complete* copy of the branches and history of the project ● Git is self-sufficient - no remote services needed for branching or commits
  • 8. Pushing & Remotes ● Unless you push your code to a remote repository, it won’t leave your machine ● You can make peer-to-peer pushes ● It’s best to manage sharing and reduce conflicts by pushing to a single designated remote location ● Pushing puts all of the historical and branching information into the remote repo
  • 9. Merges & Conflicts ● Most of the time, git can auto-merge two (or more) changesets, because they don’t overlap ● Conflicts occur when the file data changes overlap
  • 10. What does git give you? ● Complete version history ● Easy visualisation of changes ● Ability to work with multiple developers and effortlessly merge changes ● Parallel versions of source code ● Ability to switch versions or roll back changes
  • 11. Are you ready to begin?
  • 12. Core git commands ● commit ● push ● pull ● branch ● checkout ● merge ➔ Save a change ➔ Send changes to a remote ➔ Get changes from a remote ➔ Create a new branch ➔ Switch to a branch or historical version ➔ Combine branches
  • 14. Setting up a new git repository Existing repository: cd /path/to/my/repo git remote add origin ssh://git@bitbucket.org/username/bbreponame.git git push -u origin --all New repository: mkdir /path/to/your/project cd /path/to/your/project git init git remote add origin ssh://git@bitbucket.org/username/bbreponame.git
  • 16. Simple git workflow 1. Make your change(s) 2. Test it, make sure it works, and then: git commit -am “my commit message” git push origin master
  • 17. git commit -am “my commit message” git push origin master If you don’t use -am, git will open VIM, and you don’t want that. your remote location name, the one you gave it when you set up the repository, which is usually ‘origin’ the remote branch name, usually the name of your current branch
  • 18. Writing Good commit messages A good commit message is one that: ● Has a short (<50 character) description ● Uses the imperative, present tense: “change” not “changed” nor “changes” ● Includes motivation for the change and contrasts with previous behavior
  • 19. Making Good commits ● A commit message becomes your only referral point in the projects’ history ● Your commit must represent a stable point in your source code history - no half-baked commits! ● Only include relevant files and changes ● Treat every commit as if it were the final release
  • 20. The GUI is your secret weapon ● A GUI (like Sourcetree) gives an excellent overview of your repository ● It makes it possible to craft your commits on a line-by-line basis ● You can also modify your most recent commit (so long as you haven’t pushed it)
  • 22. your remote location name, the one you gave it when you set up the repository, which is usually ‘origin’ the remote branch name, usually the name of your current branch git commit -am “my commit message” git pull git push origin master if you don’t pull changes and merge locally before pushing, your push will likely be rejected
  • 23. Pulling and Merging ● git fetch will retrieve version information from a remote, but does nothing with it ● If your push is rejected, it’s likely because the remote is more up-to-date than your local branch, and you need to git pull those changes ● Pulling changes will automatically merge them if able; but if it can’t, you’ll get conflicts that will need to be resolved manually
  • 25. Dealing with conflicts ● A conflict occurs when two changesets are trying to modify the same lines of code ● Resolving conflicts involves manually picking which of the two competing modifications are accepted ● Resolving a conflict doesn’t necessarily mean that the code will still work - you’re going to have to figure that bit out yourself and edit the file manually
  • 26. Resolving conflicts is either: ● A yes/no selection between competing versions of a line of code ● Or manually editing the partial merge result to resolve the conflicts You’re going to need a GUI
  • 27. Avoiding Conflict ● Conflicts occur when you have an overlap, so don’t reformat, move or refactor code when there’s a chance someone else has also modified it ● Commit little and often ● Keep your branches up-to-date: Pull changes frequently ● Sort out your crlf settings before you start ● Some conflicts can’t be avoided
  • 29. Understanding Branches Branches: ● Are alternate versions of the working copy of your entire project, with their own history ● Can be created from, and merged back into other branches ● Can be created explicitly, or implicitly when merging two versions of the ‘same’ branch ● Allow you to work on features in isolation
  • 30. Branching strategy ● master is the stable release ● development is for work in progress ● Individual features should have their own branch ● features are branched from development ● Completed features are merged in from development ● Stable development versions are merged in from master
  • 31.
  • 32. Branching strategy in practice git checkout -b development // create and switch to development git checkout -b feature-one // create and switch to feature-one git commit -am “my awful commit message” // create a commit on feature-one git checkout development // switch back to development git merge feature-one // merge feature-one into development git checkout master // switch to master git merge development // merge development into master git push // push master branch to remote git push -u origin development // push the development branch and set its ‘upstream’
  • 33. Remote branches ● Unless you explicitly push a branch, or set an upstream for the branch, it won’t get pushed to the remote repository
  • 35. Don’t use fast-forward merges ● The default behaviour of a merge is to ‘fast forward’ the original when possible ● Fast-forwarding branches doesn’t add an extra commit for the merge, which is cleaner but loses some context
  • 36. Stashing ● A ‘stash’ is a representation of the differences between your last commit, and your current working copy. ● In order to switch branches, your current working copy must not conflict with the branch you’re checking out. ● Been working on the wrong branch? Stash changes. Checkout the correct branch. Apply stash. ● Got half-finished code but now you’ve got to drop everything to fix a bug? Stash it. Come back later.
  • 37. Git Reset ● So long as you haven’t pushed your change to a remote repository, everything is changeable ● git reset will make it completely forget your commits ● It’s useful if you’ve made changes to the wrong branch ● It can be dangerous
  • 38. Cherry Picking ● Merging branches brings across the entire history of both branches and mashes them together. ● A ‘cherry pick’ takes just the changes from a single commit and can apply them to another branch ● It’s useful, but treat it as an indication that you’ve done something wrong if you need to use it.
  • 40. Golden Rules ● Commit early, commit often (when it’s stable) ● Commit only one feature and its relevant changes at a time ● Write good commit messages ● Develop on feature branches ● Merge feature branches into development, not the other way around ● Push your changes on a regular basis
  • 41. Remember ● Git is your time machine ● Git is your safety net
  • 43. Bonus