SlideShare a Scribd company logo
secret sauce
Violeta Menéndez González
v.menendezgonzalez@surrey.ac.uk
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
What is git?
● Source code management tool
my_code.py
my_code_NEW.py
my_code_NEW2.py
my_code_final.py
my_code_DEFINITELY_FINAL.py
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
What is git?
Distributed instead of centralised:
● Each user has a full copy of the repo
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
What is git?
● It’s not GitHub!
● GitHub is an internet hosting provider that hosts your code and you can
manage it using git
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
What is git useful for?
● Reproducibility
● Collaboration
● Debugging
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
GUIs
This talk is about the commands and concepts. Everything is done on the Linux
terminal, but there are lots of GUIs that are helpful to manage your repository.
Some GUIs are integrated into your IDE (like VSCode).
For more: https://git-scm.com/downloads/guis
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Terminology
● Repository (repo): contains the project’s code and changes
● Working copy: your own copy of the repository
● Commit: a git object that represents changes to the code
● Revision: a reference to a git object. In practice, is a version of your
codebase
● Working tree or working area: where you work and make changes
● Index or staging area: changes that we want to commit
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Development history
● Tracks changes to our source code
○ Like a timeline or tree of changes
● Good and clean history is important:
○ Easier code reviewing
○ More difficult to introduce problems
○ Make debugging much easier
○ Code quality!
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Keeping track of changes with commits
● Every change is a commit with:
○ A unique identifier
○ A date
○ An author
○ A clear and concise message
○ A set of changes to the code (diff)
● Good messages for good history:
○ Short description in imperative
○ Blank line
○ Long description
● Commit ID: SHA1
○ Hash: means it’s unique!
○ It encodes history
commit 2bedc34e012778ca0abb70c14e9e40d13a81f53e
Author: Violeta Menendez Gonzalez <v.menendezgonzalez@surrey.ac.uk>
Date: Wed May 25 15:54:31 2022 +0100
Check if cuda available before using
diff --git a/train.py b/train.py
index bc31650..10ebd4f 100644
--- a/train.py
+++ b/train.py
@@ -572,4 +572,5 @@ if __name__ == '__main__':
try:
main()
finally:
- print(torch.cuda.memory_summary(abbreviated=True))
+ if torch.cuda.is_available():
+ print(torch.cuda.memory_summary(abbreviated=True))
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
History is editable
● Vital for good history
● Local history is editable:
○ Don’t modify history that has been pushed to the shared repo
● History needs to be clean:
○ Linear: commits don’t depend on later commits, we don’t want commits to break the system
○ Atomic: commits need to be concise, fixing only one bug or implementing only one feature.
Pro tip: if the commit message contains the word ‘and’ maybe think of breaking it down!
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Workflow
● Work in branches (feature branches)
● Main branch (master) for tested and clean changes
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Workflow
● Commits have an order, you may need to re-order to have a sensible history
● HEAD of a branch is the last commit
Basic commands
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Starting your repo
● git init - create a git repository
● git add <file> [<file2>...] - add files to the index for commit
● git commit - creates a commit with all the files in the staging area. Prompts
for a command message
○ Pro tip: git commit -m “Short concise message” to make the message faster
● git log - shows all the commits in your current branch
○ Pro tip: git log -p - to show the commit including code changes (diff)
○ Pro tip: git log --oneline - to show the logs in short mode
● git show <revision> - show the diff of a specific commit
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Working area
● git status - shows the status of your working area, files added, changed,
removed, conflicts, files staged…
● git diff - shows all code changes in your working area. You may have
several commits worth of changes
● git add -p - add individual changes to the index
● git diff --cached - show all changes that have been staged. If there’s
something you don’t like you can make changes
● git reset HEAD <file> - remove changes in a file from the index
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Workflow
You have several commits worth of code changes in your working tree
● git diff - see changes
● git add -p - add individual changes
● git diff --cached - double check changes you have staged for commit
● git reset HEAD <file> - remove any changes you don’t like from the
index
● git add -p - add any changes you missed
● git commit - commit changes with a good commit message
● git log -p - double check your commit looks OK
● git commit --amend - change commit at HEAD of current branch
Iterate until you have added all changes
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Demo 1: Starting a repo
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Working on branches
● Branches can be just local
● Very fast to create
● Very fast to switch between
● Very convenient for working
● Modular changes
● Consist of one or more commits
● Can be “moved around”
● Default branch is “master”, like the main trunk of the repository tree
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Branches
● git branch - show all branches in your repo (* star on you current branch)
● git branch <name> - creates branch (but not checked out)
○ Pro tip: follow a good and clear name system that describes the feature you’re developing. If
you are carrying out different independent changes, think of creating different branches and
switch between them. If you’re working with other people it can be useful to use the (?)
name/feature (i.e., violeta/data_validation)
● git checkout <branch_name> - checkout to branch
○ Pro tip: git checkout -b <name> - will create the branch AND checkout to it in one
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Merge
Once your changes are tested and the history on your branch is clean, we can
incorporate them to the main branch “master”.
● git checkout master
● git merge <branch> - merges branch ONTO master
○ You merge a branch onto your current branch, doesn’t have to be master. Make sure you
check what your current branch is!!
NOTE: This can cause merge conflicts. DON’T PANIC
git status will tell us what to do
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Demo 2: Branch and merge
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Merge conflicts
● They can occur when we try to modify the same line in two different ways
● git status - shows which file has the conflict
● Edit file:
○ You can keep the current changes
○ You can keep the old changes
○ Or you can modify them to look how you like
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Revisions
Revisions are revised versions of our code. Each commit represents a revision of our
code.
● git checkout <commit> - checkout a specific revision of our code. We are in a
‘detached HEAD’, we are not in a branch any more.
● We can make experimental changes, build or test our system without impacting any
branches.
● git checkout -b <name> - if we want to save the new commits in a branch
or
● git checkout <previos_branch> - to go back to where we were
○ Pro Tip: you can also use ‘git checkout -’
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Stash
If we have uncommitted changes in our index and we want to checkout a different
revision, they may go into conflict!
● git stash - stashes all changes “away”, leaving a clean working directory
● git stash list - shows all stashed changes
● git stash apply - to restore the changes you saved
● git stash pop - apply changes AND remove them from the list
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Resetting revision
● git reset <commit> - set your current revision and index area to a certain
state
○ --mixed - Resets index but not working tree. Sets HEAD to commit,
discards all history, changes are kept in working tree. (default)
○ --soft - Leaves index and working tree untouched. Sets HEAD to
commit, discards all history, leaves changes staged for commit
○ --hard - Resets both index and working tree. Resets HEAD, history
AND working tree. You lose all code!!!
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Demo 3: stash and reset
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Rebase
Rebase is used to integrate history from one branch into another branch. History is
rewritten, we want to rewrite it to make it better!
● You have a working branch
● Someone else pushes to master in the remote repo
● You want to push your changes, but they may conflict with the remote repo
● You want to update the repo to reflect the other person’s changes
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Rebase
● git rebase <branch> - rebases your current branch over branch. All
commits from branch are now in your history.
○ git checkout branchA
○ git rebase master
There may be conflicts (because we may have changes that
apply to places that are different now due to the new commits!)
BUT
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Resolve conflicts
● git status will tell you which files are in conflict!
● Make relevant changes
● git add <your changes>
● git rebase --continue
If we changed our minds:
● git rebase --abort
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Demo 4: Rebase and solve conflict
Note: commit SHAs change, as history has changed
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Interactive rebase
● More flexible rebase
● Useful for:
○ Integrating changes from code review
○ Making history simple and linear
○ Making every point in history valid
○ Making sure commits don’t undo each other
○ No “oops” commits
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Interactive rebase
● git rebase -i <commit> - rebase all commits newer than <commit>
Opens a list of commits with options to modify, reorder or delete them:
● p (pick) - leave as is (default)
● r (reword) - change message
● e (edit) - modify contents of commit
● s (squash) - combine with previous commit
CAREFUL: rebase is destructive. Make sure you in the correct branch, and back up!
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Splitting commits
● Mark commit for edit
● git reset HEAD^ - reset log to previous commit leaving changes in tree
● git add -p
● git commit
● Repeat until done
● git rebase --continue
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Demo 5: Interactive rebase and split commit
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Debugging
● git blame <file> - shows the commit that introduced each line of a file.
● git bisect - Amazing debugging tool. Prompts you to give a good and a
bad commit, then uses a bisecting algorithm to checkout commits in between.
You then run your test and mark the commit as good/bad. After a few
iterations git tells you which commit introduced the bug!! Magic
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Debugging
● git blame <file> - shows the commit that introduced each line of a file.
● git bisect - Amazing debugging tool. Prompts you to give a good and a
bad commit, then uses a bisecting algorithm to checkout commits in between.
You then run your test and mark the commit as good/bad. After a few
iterations git tells you which commit introduced the bug!! Magic
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Debugging
● git blame <file> - shows the commit that introduced each line of a file.
● git bisect - Amazing debugging tool. Prompts you to give a good and a
bad commit, then uses a bisecting algorithm to checkout commits in between.
You then run your test and mark the commit as good/bad. After a few
iterations git tells you which commit introduced the bug!! Magic
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Debugging
● git blame <file> - shows the commit that introduced each line of a file.
● git bisect - Amazing debugging tool. Prompts you to give a good and a
bad commit, then uses a bisecting algorithm to checkout commits in between.
You then run your test and mark the commit as good/bad. After a few
iterations git tells you which commit introduced the bug!! Magic
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Ranges
● git diff <commit2>..<commit4> - shows all changes between two
commits (older..newer)
○ git diff <commit2>..HEAD - all changes from commit2 until present
● git log <commit2>..<commit4> - shows all commits between commit2
and commit 4
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Remotes
● Remotes are repositories that are backed up in some server (e.g. GitHub )
● Use for collaboration and backup
● git clone <URL> - retrieves a repository into a directory
○ ssh://[user@]host.xz[:port]/path/to/repo.git/
○ git://host.xz[:port]/path/to/repo.git/
○ http[s]://host.xz[:port]/path/to/repo.git/
git is the
baaeest
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Remotes
● You can have several remotes. Default is origin.
○ e.g., If you want to make changes to a repo that you don’t want to be public
● git add remote <name> <remote> - adds a new remote
● git checkout <remote>/<branch> - checks out a branch from a
specific remote
● git remote -v - show tracked remotes
● git rename <old> <new> - change name of remote
$ git remote -v
origin gitlab@gitlab.eps.surrey.ac.uk:violeta/mystery-project.git (fetch)
origin gitlab@gitlab.eps.surrey.ac.uk:violeta/mystery-project.git (push)
upstream git@github.com:alex/mystery-project.git (fetch)
upstream git@github.com:alex/mystery-project.git (push)
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Remotes
● git fetch [<remote>] - retrieves all references, doesn’t modify working
copy
● git pull [<remote> [<branch>]] - retrieves all changes from remote
into your local branch (default: origin, master)
● git push [<remote> [<branch>]] - pushes your local changes to
branch in remote
Attention!! Pull can create conflicts
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Demo 6: Remotes
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
If everything else fails…
Git Basics walkthough to all basic concept and commands of git
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Reflog
Git keeps track of every single branch change, and stores it in the Reference Log
● Each change is an entry in the reflog with a reference
● The state can be restored to any reference
● If you mess up… just reset it back to before it happened!
● Only local
● git reflog - list all entries
● git reset <sha1>
Rebase
Pull
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Demo 7: Reflog
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Resources
● Documentation: https://git-scm.com/
● git <command> --help
● Man pages:
○ man git-log
○ man git-add
○ etc
● Stackoverflow is your friend
● Special thanks to Alan Ott’s talk Git like a Pro:
https://youtu.be/H2annVAHKPE?t=19199
Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
Thank you!!!
● Next Monthly Mini Hack in June - to be announced

More Related Content

Similar to Git Basics walkthough to all basic concept and commands of git

Command line git
Command line gitCommand line git
Command line git
Manos Emmanouilidis
 
Git tech talk
Git tech talkGit tech talk
Git tech talk
razasayed
 
3 Git
3 Git3 Git
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
Robert Lee-Cann
 
Gn unify git
Gn unify gitGn unify git
Gn unify git
Priyanka Nag
 
Histedit Mercurial Extension
Histedit Mercurial ExtensionHistedit Mercurial Extension
Histedit Mercurial Extension
Manel Villar
 
Git Init (Introduction to Git)
Git Init (Introduction to Git)Git Init (Introduction to Git)
Git Init (Introduction to Git)
GDSC UofT Mississauga
 
GIT
GITGIT
git2.ppt
git2.pptgit2.ppt
git2.ppt
ssusered2ec2
 
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a gitVincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
VincitOy
 
Git essentials
Git essentialsGit essentials
Git essentials
Otto Kekäläinen
 
Git tips
Git tipsGit tips
Git tips
Arthur Shvetsov
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control system
Kumaresh Chandra Baruri
 
Git and github fundamentals
Git and github fundamentalsGit and github fundamentals
Git and github fundamentals
RajKharvar
 
How to git easily in day to-day work
How to git easily in day to-day workHow to git easily in day to-day work
How to git easily in day to-day work
Alena Radkevich
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
Tagged Social
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
Bimal Jain
 
Git presentation bixlabs
Git presentation bixlabsGit presentation bixlabs
Git presentation bixlabs
Bixlabs
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
Otto Kekäläinen
 
GIT_training_SoftServeBulgaria2016
GIT_training_SoftServeBulgaria2016GIT_training_SoftServeBulgaria2016
GIT_training_SoftServeBulgaria2016
Peter Denev
 

Similar to Git Basics walkthough to all basic concept and commands of git (20)

Command line git
Command line gitCommand line git
Command line git
 
Git tech talk
Git tech talkGit tech talk
Git tech talk
 
3 Git
3 Git3 Git
3 Git
 
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
 
Gn unify git
Gn unify gitGn unify git
Gn unify git
 
Histedit Mercurial Extension
Histedit Mercurial ExtensionHistedit Mercurial Extension
Histedit Mercurial Extension
 
Git Init (Introduction to Git)
Git Init (Introduction to Git)Git Init (Introduction to Git)
Git Init (Introduction to Git)
 
GIT
GITGIT
GIT
 
git2.ppt
git2.pptgit2.ppt
git2.ppt
 
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a gitVincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
 
Git essentials
Git essentialsGit essentials
Git essentials
 
Git tips
Git tipsGit tips
Git tips
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control system
 
Git and github fundamentals
Git and github fundamentalsGit and github fundamentals
Git and github fundamentals
 
How to git easily in day to-day work
How to git easily in day to-day workHow to git easily in day to-day work
How to git easily in day to-day work
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Git presentation bixlabs
Git presentation bixlabsGit presentation bixlabs
Git presentation bixlabs
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
 
GIT_training_SoftServeBulgaria2016
GIT_training_SoftServeBulgaria2016GIT_training_SoftServeBulgaria2016
GIT_training_SoftServeBulgaria2016
 

More from DivyanshGupta922023

Git mercurial - Git basics , features and commands
Git mercurial - Git basics , features and commandsGit mercurial - Git basics , features and commands
Git mercurial - Git basics , features and commands
DivyanshGupta922023
 
Fundamentals and basics of Git and commands
Fundamentals and basics of Git and commandsFundamentals and basics of Git and commands
Fundamentals and basics of Git and commands
DivyanshGupta922023
 
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
DivyanshGupta922023
 
DevOps The Buzzword - everything about devops
DevOps The Buzzword - everything about devopsDevOps The Buzzword - everything about devops
DevOps The Buzzword - everything about devops
DivyanshGupta922023
 
jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applications
DivyanshGupta922023
 
Next.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptxNext.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptx
DivyanshGupta922023
 
Management+team.pptx
Management+team.pptxManagement+team.pptx
Management+team.pptx
DivyanshGupta922023
 
DHC Microbiome Presentation 4-23-19.pptx
DHC Microbiome Presentation 4-23-19.pptxDHC Microbiome Presentation 4-23-19.pptx
DHC Microbiome Presentation 4-23-19.pptx
DivyanshGupta922023
 
developer-burnout.pdf
developer-burnout.pdfdeveloper-burnout.pdf
developer-burnout.pdf
DivyanshGupta922023
 
AzureIntro.pptx
AzureIntro.pptxAzureIntro.pptx
AzureIntro.pptx
DivyanshGupta922023
 
api-driven-development.pdf
api-driven-development.pdfapi-driven-development.pdf
api-driven-development.pdf
DivyanshGupta922023
 
Internet of Things.pptx
Internet of Things.pptxInternet of Things.pptx
Internet of Things.pptx
DivyanshGupta922023
 
Functional JS+ ES6.pptx
Functional JS+ ES6.pptxFunctional JS+ ES6.pptx
Functional JS+ ES6.pptx
DivyanshGupta922023
 
AAAI19-Open.pptx
AAAI19-Open.pptxAAAI19-Open.pptx
AAAI19-Open.pptx
DivyanshGupta922023
 
10-security-concepts-lightning-talk 1of2.pptx
10-security-concepts-lightning-talk 1of2.pptx10-security-concepts-lightning-talk 1of2.pptx
10-security-concepts-lightning-talk 1of2.pptx
DivyanshGupta922023
 
Introduction to Directed Acyclic Graphs.pptx
Introduction to Directed Acyclic Graphs.pptxIntroduction to Directed Acyclic Graphs.pptx
Introduction to Directed Acyclic Graphs.pptx
DivyanshGupta922023
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
DivyanshGupta922023
 
01-React js Intro.pptx
01-React js Intro.pptx01-React js Intro.pptx
01-React js Intro.pptx
DivyanshGupta922023
 
Nextjs13.pptx
Nextjs13.pptxNextjs13.pptx
Nextjs13.pptx
DivyanshGupta922023
 

More from DivyanshGupta922023 (19)

Git mercurial - Git basics , features and commands
Git mercurial - Git basics , features and commandsGit mercurial - Git basics , features and commands
Git mercurial - Git basics , features and commands
 
Fundamentals and basics of Git and commands
Fundamentals and basics of Git and commandsFundamentals and basics of Git and commands
Fundamentals and basics of Git and commands
 
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
(Public) FedCM BlinkOn 16 fedcm and privacy sandbox apis
 
DevOps The Buzzword - everything about devops
DevOps The Buzzword - everything about devopsDevOps The Buzzword - everything about devops
DevOps The Buzzword - everything about devops
 
jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applications
 
Next.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptxNext.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptx
 
Management+team.pptx
Management+team.pptxManagement+team.pptx
Management+team.pptx
 
DHC Microbiome Presentation 4-23-19.pptx
DHC Microbiome Presentation 4-23-19.pptxDHC Microbiome Presentation 4-23-19.pptx
DHC Microbiome Presentation 4-23-19.pptx
 
developer-burnout.pdf
developer-burnout.pdfdeveloper-burnout.pdf
developer-burnout.pdf
 
AzureIntro.pptx
AzureIntro.pptxAzureIntro.pptx
AzureIntro.pptx
 
api-driven-development.pdf
api-driven-development.pdfapi-driven-development.pdf
api-driven-development.pdf
 
Internet of Things.pptx
Internet of Things.pptxInternet of Things.pptx
Internet of Things.pptx
 
Functional JS+ ES6.pptx
Functional JS+ ES6.pptxFunctional JS+ ES6.pptx
Functional JS+ ES6.pptx
 
AAAI19-Open.pptx
AAAI19-Open.pptxAAAI19-Open.pptx
AAAI19-Open.pptx
 
10-security-concepts-lightning-talk 1of2.pptx
10-security-concepts-lightning-talk 1of2.pptx10-security-concepts-lightning-talk 1of2.pptx
10-security-concepts-lightning-talk 1of2.pptx
 
Introduction to Directed Acyclic Graphs.pptx
Introduction to Directed Acyclic Graphs.pptxIntroduction to Directed Acyclic Graphs.pptx
Introduction to Directed Acyclic Graphs.pptx
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
01-React js Intro.pptx
01-React js Intro.pptx01-React js Intro.pptx
01-React js Intro.pptx
 
Nextjs13.pptx
Nextjs13.pptxNextjs13.pptx
Nextjs13.pptx
 

Recently uploaded

Digital Image Processing - Module 4 Chapter 2
Digital Image Processing - Module 4 Chapter 2Digital Image Processing - Module 4 Chapter 2
Digital Image Processing - Module 4 Chapter 2
821priyankaj
 
carpentry-11-module-1.docx 1 identifying tools
carpentry-11-module-1.docx 1 identifying toolscarpentry-11-module-1.docx 1 identifying tools
carpentry-11-module-1.docx 1 identifying tools
ChristopherAltizen2
 
ECONOMIC FEASIBILITY AND ENVIRONMENTAL IMPLICATIONS OF PERMEABLE PAVEMENT IN ...
ECONOMIC FEASIBILITY AND ENVIRONMENTAL IMPLICATIONS OF PERMEABLE PAVEMENT IN ...ECONOMIC FEASIBILITY AND ENVIRONMENTAL IMPLICATIONS OF PERMEABLE PAVEMENT IN ...
ECONOMIC FEASIBILITY AND ENVIRONMENTAL IMPLICATIONS OF PERMEABLE PAVEMENT IN ...
Fady M. A Hassouna
 
Cisco Intersight Technical OverView.pptx
Cisco Intersight Technical OverView.pptxCisco Intersight Technical OverView.pptx
Cisco Intersight Technical OverView.pptx
Duy Nguyen
 
Chapter 1 Introduction to Software Engineering and Process Models.pdf
Chapter 1 Introduction to Software Engineering and Process Models.pdfChapter 1 Introduction to Software Engineering and Process Models.pdf
Chapter 1 Introduction to Software Engineering and Process Models.pdf
MeghaGupta952452
 
the potential for the development of autonomous aircraft
the potential for the development of autonomous aircraftthe potential for the development of autonomous aircraft
the potential for the development of autonomous aircraft
huseindihon
 
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
AsiimweJulius2
 
The Control of Relative Humidity & Moisture Content in The Air
The Control of Relative Humidity & Moisture Content in The AirThe Control of Relative Humidity & Moisture Content in The Air
The Control of Relative Humidity & Moisture Content in The Air
Ashraf Ismail
 
How to Formulate A Good Research Question
How to Formulate A  Good Research QuestionHow to Formulate A  Good Research Question
How to Formulate A Good Research Question
rkpv2002
 
III B.TECH CSE_flutter Lab manual (1).docx
III B.TECH CSE_flutter Lab manual (1).docxIII B.TECH CSE_flutter Lab manual (1).docx
III B.TECH CSE_flutter Lab manual (1).docx
divijareddy0502
 
# Smart Parking Management System.pptx using IOT
# Smart Parking Management System.pptx using IOT# Smart Parking Management System.pptx using IOT
# Smart Parking Management System.pptx using IOT
Yesh20
 
杨洋李一桐做爱视频流出【网芷:ht28.co】国产国产午夜精华>>>[网趾:ht28.co】]<<<
杨洋李一桐做爱视频流出【网芷:ht28.co】国产国产午夜精华>>>[网趾:ht28.co】]<<<杨洋李一桐做爱视频流出【网芷:ht28.co】国产国产午夜精华>>>[网趾:ht28.co】]<<<
杨洋李一桐做爱视频流出【网芷:ht28.co】国产国产午夜精华>>>[网趾:ht28.co】]<<<
amzhoxvzidbke
 
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagneEAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
idelewebmestre
 
NOVEC 1230 Fire Suppression System Presentation
NOVEC 1230 Fire Suppression System PresentationNOVEC 1230 Fire Suppression System Presentation
NOVEC 1230 Fire Suppression System Presentation
miniruwan1
 
TestRigor - Element Location Rules and UI Grid system
TestRigor - Element Location Rules and UI Grid systemTestRigor - Element Location Rules and UI Grid system
TestRigor - Element Location Rules and UI Grid system
artembondar5
 
Concepts of Automatic Block Signalling.ppt
Concepts of Automatic Block Signalling.pptConcepts of Automatic Block Signalling.ppt
Concepts of Automatic Block Signalling.ppt
princeshah76
 
System Analysis and Design in a changing world 5th edition
System Analysis and Design in a changing world 5th editionSystem Analysis and Design in a changing world 5th edition
System Analysis and Design in a changing world 5th edition
mnassar75g
 
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptxOME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
shanmugamram247
 
ANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
ANATOMY OF SOA - Thomas Erl - Service Oriented ArchitectureANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
ANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
Divya Rajasekar
 
Safety Operating Procedure for Testing Lifting Tackles
Safety Operating Procedure for Testing Lifting TacklesSafety Operating Procedure for Testing Lifting Tackles
Safety Operating Procedure for Testing Lifting Tackles
ssuserfcf701
 

Recently uploaded (20)

Digital Image Processing - Module 4 Chapter 2
Digital Image Processing - Module 4 Chapter 2Digital Image Processing - Module 4 Chapter 2
Digital Image Processing - Module 4 Chapter 2
 
carpentry-11-module-1.docx 1 identifying tools
carpentry-11-module-1.docx 1 identifying toolscarpentry-11-module-1.docx 1 identifying tools
carpentry-11-module-1.docx 1 identifying tools
 
ECONOMIC FEASIBILITY AND ENVIRONMENTAL IMPLICATIONS OF PERMEABLE PAVEMENT IN ...
ECONOMIC FEASIBILITY AND ENVIRONMENTAL IMPLICATIONS OF PERMEABLE PAVEMENT IN ...ECONOMIC FEASIBILITY AND ENVIRONMENTAL IMPLICATIONS OF PERMEABLE PAVEMENT IN ...
ECONOMIC FEASIBILITY AND ENVIRONMENTAL IMPLICATIONS OF PERMEABLE PAVEMENT IN ...
 
Cisco Intersight Technical OverView.pptx
Cisco Intersight Technical OverView.pptxCisco Intersight Technical OverView.pptx
Cisco Intersight Technical OverView.pptx
 
Chapter 1 Introduction to Software Engineering and Process Models.pdf
Chapter 1 Introduction to Software Engineering and Process Models.pdfChapter 1 Introduction to Software Engineering and Process Models.pdf
Chapter 1 Introduction to Software Engineering and Process Models.pdf
 
the potential for the development of autonomous aircraft
the potential for the development of autonomous aircraftthe potential for the development of autonomous aircraft
the potential for the development of autonomous aircraft
 
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
 
The Control of Relative Humidity & Moisture Content in The Air
The Control of Relative Humidity & Moisture Content in The AirThe Control of Relative Humidity & Moisture Content in The Air
The Control of Relative Humidity & Moisture Content in The Air
 
How to Formulate A Good Research Question
How to Formulate A  Good Research QuestionHow to Formulate A  Good Research Question
How to Formulate A Good Research Question
 
III B.TECH CSE_flutter Lab manual (1).docx
III B.TECH CSE_flutter Lab manual (1).docxIII B.TECH CSE_flutter Lab manual (1).docx
III B.TECH CSE_flutter Lab manual (1).docx
 
# Smart Parking Management System.pptx using IOT
# Smart Parking Management System.pptx using IOT# Smart Parking Management System.pptx using IOT
# Smart Parking Management System.pptx using IOT
 
杨洋李一桐做爱视频流出【网芷:ht28.co】国产国产午夜精华>>>[网趾:ht28.co】]<<<
杨洋李一桐做爱视频流出【网芷:ht28.co】国产国产午夜精华>>>[网趾:ht28.co】]<<<杨洋李一桐做爱视频流出【网芷:ht28.co】国产国产午夜精华>>>[网趾:ht28.co】]<<<
杨洋李一桐做爱视频流出【网芷:ht28.co】国产国产午夜精华>>>[网趾:ht28.co】]<<<
 
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagneEAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
 
NOVEC 1230 Fire Suppression System Presentation
NOVEC 1230 Fire Suppression System PresentationNOVEC 1230 Fire Suppression System Presentation
NOVEC 1230 Fire Suppression System Presentation
 
TestRigor - Element Location Rules and UI Grid system
TestRigor - Element Location Rules and UI Grid systemTestRigor - Element Location Rules and UI Grid system
TestRigor - Element Location Rules and UI Grid system
 
Concepts of Automatic Block Signalling.ppt
Concepts of Automatic Block Signalling.pptConcepts of Automatic Block Signalling.ppt
Concepts of Automatic Block Signalling.ppt
 
System Analysis and Design in a changing world 5th edition
System Analysis and Design in a changing world 5th editionSystem Analysis and Design in a changing world 5th edition
System Analysis and Design in a changing world 5th edition
 
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptxOME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
 
ANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
ANATOMY OF SOA - Thomas Erl - Service Oriented ArchitectureANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
ANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
 
Safety Operating Procedure for Testing Lifting Tackles
Safety Operating Procedure for Testing Lifting TacklesSafety Operating Procedure for Testing Lifting Tackles
Safety Operating Procedure for Testing Lifting Tackles
 

Git Basics walkthough to all basic concept and commands of git

  • 1. secret sauce Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
  • 2. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk What is git? ● Source code management tool my_code.py my_code_NEW.py my_code_NEW2.py my_code_final.py my_code_DEFINITELY_FINAL.py
  • 3. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk What is git? Distributed instead of centralised: ● Each user has a full copy of the repo
  • 4. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk What is git? ● It’s not GitHub! ● GitHub is an internet hosting provider that hosts your code and you can manage it using git
  • 5. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk What is git useful for? ● Reproducibility ● Collaboration ● Debugging
  • 6. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk GUIs This talk is about the commands and concepts. Everything is done on the Linux terminal, but there are lots of GUIs that are helpful to manage your repository. Some GUIs are integrated into your IDE (like VSCode). For more: https://git-scm.com/downloads/guis
  • 7. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Terminology ● Repository (repo): contains the project’s code and changes ● Working copy: your own copy of the repository ● Commit: a git object that represents changes to the code ● Revision: a reference to a git object. In practice, is a version of your codebase ● Working tree or working area: where you work and make changes ● Index or staging area: changes that we want to commit
  • 8. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Development history ● Tracks changes to our source code ○ Like a timeline or tree of changes ● Good and clean history is important: ○ Easier code reviewing ○ More difficult to introduce problems ○ Make debugging much easier ○ Code quality!
  • 9. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Keeping track of changes with commits ● Every change is a commit with: ○ A unique identifier ○ A date ○ An author ○ A clear and concise message ○ A set of changes to the code (diff) ● Good messages for good history: ○ Short description in imperative ○ Blank line ○ Long description ● Commit ID: SHA1 ○ Hash: means it’s unique! ○ It encodes history commit 2bedc34e012778ca0abb70c14e9e40d13a81f53e Author: Violeta Menendez Gonzalez <v.menendezgonzalez@surrey.ac.uk> Date: Wed May 25 15:54:31 2022 +0100 Check if cuda available before using diff --git a/train.py b/train.py index bc31650..10ebd4f 100644 --- a/train.py +++ b/train.py @@ -572,4 +572,5 @@ if __name__ == '__main__': try: main() finally: - print(torch.cuda.memory_summary(abbreviated=True)) + if torch.cuda.is_available(): + print(torch.cuda.memory_summary(abbreviated=True))
  • 10. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk History is editable ● Vital for good history ● Local history is editable: ○ Don’t modify history that has been pushed to the shared repo ● History needs to be clean: ○ Linear: commits don’t depend on later commits, we don’t want commits to break the system ○ Atomic: commits need to be concise, fixing only one bug or implementing only one feature. Pro tip: if the commit message contains the word ‘and’ maybe think of breaking it down!
  • 11. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Workflow ● Work in branches (feature branches) ● Main branch (master) for tested and clean changes
  • 12. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Workflow ● Commits have an order, you may need to re-order to have a sensible history ● HEAD of a branch is the last commit
  • 14. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Starting your repo ● git init - create a git repository ● git add <file> [<file2>...] - add files to the index for commit ● git commit - creates a commit with all the files in the staging area. Prompts for a command message ○ Pro tip: git commit -m “Short concise message” to make the message faster ● git log - shows all the commits in your current branch ○ Pro tip: git log -p - to show the commit including code changes (diff) ○ Pro tip: git log --oneline - to show the logs in short mode ● git show <revision> - show the diff of a specific commit
  • 15. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Working area ● git status - shows the status of your working area, files added, changed, removed, conflicts, files staged… ● git diff - shows all code changes in your working area. You may have several commits worth of changes ● git add -p - add individual changes to the index ● git diff --cached - show all changes that have been staged. If there’s something you don’t like you can make changes ● git reset HEAD <file> - remove changes in a file from the index
  • 16. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Workflow You have several commits worth of code changes in your working tree ● git diff - see changes ● git add -p - add individual changes ● git diff --cached - double check changes you have staged for commit ● git reset HEAD <file> - remove any changes you don’t like from the index ● git add -p - add any changes you missed ● git commit - commit changes with a good commit message ● git log -p - double check your commit looks OK ● git commit --amend - change commit at HEAD of current branch Iterate until you have added all changes
  • 17. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Demo 1: Starting a repo
  • 18. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Working on branches ● Branches can be just local ● Very fast to create ● Very fast to switch between ● Very convenient for working ● Modular changes ● Consist of one or more commits ● Can be “moved around” ● Default branch is “master”, like the main trunk of the repository tree
  • 19. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Branches ● git branch - show all branches in your repo (* star on you current branch) ● git branch <name> - creates branch (but not checked out) ○ Pro tip: follow a good and clear name system that describes the feature you’re developing. If you are carrying out different independent changes, think of creating different branches and switch between them. If you’re working with other people it can be useful to use the (?) name/feature (i.e., violeta/data_validation) ● git checkout <branch_name> - checkout to branch ○ Pro tip: git checkout -b <name> - will create the branch AND checkout to it in one
  • 20. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Merge Once your changes are tested and the history on your branch is clean, we can incorporate them to the main branch “master”. ● git checkout master ● git merge <branch> - merges branch ONTO master ○ You merge a branch onto your current branch, doesn’t have to be master. Make sure you check what your current branch is!! NOTE: This can cause merge conflicts. DON’T PANIC git status will tell us what to do
  • 21. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Demo 2: Branch and merge
  • 22. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Merge conflicts ● They can occur when we try to modify the same line in two different ways ● git status - shows which file has the conflict ● Edit file: ○ You can keep the current changes ○ You can keep the old changes ○ Or you can modify them to look how you like
  • 23. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Revisions Revisions are revised versions of our code. Each commit represents a revision of our code. ● git checkout <commit> - checkout a specific revision of our code. We are in a ‘detached HEAD’, we are not in a branch any more. ● We can make experimental changes, build or test our system without impacting any branches. ● git checkout -b <name> - if we want to save the new commits in a branch or ● git checkout <previos_branch> - to go back to where we were ○ Pro Tip: you can also use ‘git checkout -’
  • 24. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Stash If we have uncommitted changes in our index and we want to checkout a different revision, they may go into conflict! ● git stash - stashes all changes “away”, leaving a clean working directory ● git stash list - shows all stashed changes ● git stash apply - to restore the changes you saved ● git stash pop - apply changes AND remove them from the list
  • 25. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Resetting revision ● git reset <commit> - set your current revision and index area to a certain state ○ --mixed - Resets index but not working tree. Sets HEAD to commit, discards all history, changes are kept in working tree. (default) ○ --soft - Leaves index and working tree untouched. Sets HEAD to commit, discards all history, leaves changes staged for commit ○ --hard - Resets both index and working tree. Resets HEAD, history AND working tree. You lose all code!!!
  • 26. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Demo 3: stash and reset
  • 27. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Rebase Rebase is used to integrate history from one branch into another branch. History is rewritten, we want to rewrite it to make it better! ● You have a working branch ● Someone else pushes to master in the remote repo ● You want to push your changes, but they may conflict with the remote repo ● You want to update the repo to reflect the other person’s changes
  • 28. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Rebase ● git rebase <branch> - rebases your current branch over branch. All commits from branch are now in your history. ○ git checkout branchA ○ git rebase master There may be conflicts (because we may have changes that apply to places that are different now due to the new commits!) BUT
  • 29. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk
  • 30. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Resolve conflicts ● git status will tell you which files are in conflict! ● Make relevant changes ● git add <your changes> ● git rebase --continue If we changed our minds: ● git rebase --abort
  • 31. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Demo 4: Rebase and solve conflict Note: commit SHAs change, as history has changed
  • 32. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Interactive rebase ● More flexible rebase ● Useful for: ○ Integrating changes from code review ○ Making history simple and linear ○ Making every point in history valid ○ Making sure commits don’t undo each other ○ No “oops” commits
  • 33. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Interactive rebase ● git rebase -i <commit> - rebase all commits newer than <commit> Opens a list of commits with options to modify, reorder or delete them: ● p (pick) - leave as is (default) ● r (reword) - change message ● e (edit) - modify contents of commit ● s (squash) - combine with previous commit CAREFUL: rebase is destructive. Make sure you in the correct branch, and back up!
  • 34. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Splitting commits ● Mark commit for edit ● git reset HEAD^ - reset log to previous commit leaving changes in tree ● git add -p ● git commit ● Repeat until done ● git rebase --continue
  • 35. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Demo 5: Interactive rebase and split commit
  • 36. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Debugging ● git blame <file> - shows the commit that introduced each line of a file. ● git bisect - Amazing debugging tool. Prompts you to give a good and a bad commit, then uses a bisecting algorithm to checkout commits in between. You then run your test and mark the commit as good/bad. After a few iterations git tells you which commit introduced the bug!! Magic
  • 37. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Debugging ● git blame <file> - shows the commit that introduced each line of a file. ● git bisect - Amazing debugging tool. Prompts you to give a good and a bad commit, then uses a bisecting algorithm to checkout commits in between. You then run your test and mark the commit as good/bad. After a few iterations git tells you which commit introduced the bug!! Magic
  • 38. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Debugging ● git blame <file> - shows the commit that introduced each line of a file. ● git bisect - Amazing debugging tool. Prompts you to give a good and a bad commit, then uses a bisecting algorithm to checkout commits in between. You then run your test and mark the commit as good/bad. After a few iterations git tells you which commit introduced the bug!! Magic
  • 39. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Debugging ● git blame <file> - shows the commit that introduced each line of a file. ● git bisect - Amazing debugging tool. Prompts you to give a good and a bad commit, then uses a bisecting algorithm to checkout commits in between. You then run your test and mark the commit as good/bad. After a few iterations git tells you which commit introduced the bug!! Magic
  • 40. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Ranges ● git diff <commit2>..<commit4> - shows all changes between two commits (older..newer) ○ git diff <commit2>..HEAD - all changes from commit2 until present ● git log <commit2>..<commit4> - shows all commits between commit2 and commit 4
  • 41. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Remotes ● Remotes are repositories that are backed up in some server (e.g. GitHub ) ● Use for collaboration and backup ● git clone <URL> - retrieves a repository into a directory ○ ssh://[user@]host.xz[:port]/path/to/repo.git/ ○ git://host.xz[:port]/path/to/repo.git/ ○ http[s]://host.xz[:port]/path/to/repo.git/ git is the baaeest
  • 42. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Remotes ● You can have several remotes. Default is origin. ○ e.g., If you want to make changes to a repo that you don’t want to be public ● git add remote <name> <remote> - adds a new remote ● git checkout <remote>/<branch> - checks out a branch from a specific remote ● git remote -v - show tracked remotes ● git rename <old> <new> - change name of remote $ git remote -v origin gitlab@gitlab.eps.surrey.ac.uk:violeta/mystery-project.git (fetch) origin gitlab@gitlab.eps.surrey.ac.uk:violeta/mystery-project.git (push) upstream git@github.com:alex/mystery-project.git (fetch) upstream git@github.com:alex/mystery-project.git (push)
  • 43. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Remotes ● git fetch [<remote>] - retrieves all references, doesn’t modify working copy ● git pull [<remote> [<branch>]] - retrieves all changes from remote into your local branch (default: origin, master) ● git push [<remote> [<branch>]] - pushes your local changes to branch in remote Attention!! Pull can create conflicts
  • 44. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Demo 6: Remotes
  • 45. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk If everything else fails…
  • 47. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Reflog Git keeps track of every single branch change, and stores it in the Reference Log ● Each change is an entry in the reflog with a reference ● The state can be restored to any reference ● If you mess up… just reset it back to before it happened! ● Only local ● git reflog - list all entries ● git reset <sha1> Rebase Pull
  • 48. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Demo 7: Reflog
  • 49. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Resources ● Documentation: https://git-scm.com/ ● git <command> --help ● Man pages: ○ man git-log ○ man git-add ○ etc ● Stackoverflow is your friend ● Special thanks to Alan Ott’s talk Git like a Pro: https://youtu.be/H2annVAHKPE?t=19199
  • 50. Violeta Menéndez González v.menendezgonzalez@surrey.ac.uk Thank you!!! ● Next Monthly Mini Hack in June - to be announced