A Quick Intro To Git and Github: Miguel L Azaro-Gredilla
A Quick Intro To Git and Github: Miguel L Azaro-Gredilla
Miguel Lazaro-Gredilla
miguel@tsc.uc3m.es
June 2014
Machine Learning Group
http://www.tsc.uc3m.es/~miguel/MLG/
Contents
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Git
I
1/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Git
I
1/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Git
I
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
2/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
4/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
5/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Github pricing
6/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Contents
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Cloning a repository
This clones a repository (and its full history) to your computer
$ git clone https://github.com/lazarox/charla.git
I
charla/.gitignore
charla/.gitattributes
8/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
9/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
10/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Committing changes
Commit everything from the staging area to the repository (locally)
$ git commit -m I improved all files
The message is compulsory! Otherwise, youd avoid it and soon
forget that commits purpose
Each commit has an identifying SHA-1 hash and comment. You
can roll back to past commits.
You can stage everything that is tracked and commit in a single
step using
$ git commit -a -m I improved all files
ACTION: Commit everything.
12/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
13/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
14/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
15/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
17/31
Contents
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Branching
18/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Several commits
19/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
22/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Basic merge
Given this structure
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Deleting branches
After the previous merge, we get
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Sample workflow
26/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Remote repositories
The remote repository and its local snapshot may diverge
Contents
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Using Issues
28/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Pull requests
29/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
30/31
Contents
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Exercise
1. Make sure your local repo is up-to-date (i.e, pull)
2. Dont interact again with the server unless you are told to
31/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Exercise
1. Make sure your local repo is up-to-date (i.e, pull)
2. Dont interact again with the server unless you are told to
3. Make a branch called myfixName (use your own name) at the
current commit and switch to it
31/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Exercise
1. Make sure your local repo is up-to-date (i.e, pull)
2. Dont interact again with the server unless you are told to
3. Make a branch called myfixName (use your own name) at the
current commit and switch to it
4. Go to folder fibos and fix only the file with your name on it
31/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Exercise
1. Make sure your local repo is up-to-date (i.e, pull)
2. Dont interact again with the server unless you are told to
3. Make a branch called myfixName (use your own name) at the
current commit and switch to it
4. Go to folder fibos and fix only the file with your name on it
5. There is a bug that requires your immediate attention! Switch
to branch master and pull new files from server
6. Go to folder factorials and fix only the file with your name
7. Push corrections in master to server
31/31
Introduction
Basic Git
Branching in Git
GitHub
Hands-on practice
Exercise
1. Make sure your local repo is up-to-date (i.e, pull)
2. Dont interact again with the server unless you are told to
3. Make a branch called myfixName (use your own name) at the
current commit and switch to it
4. Go to folder fibos and fix only the file with your name on it
5. There is a bug that requires your immediate attention! Switch
to branch master and pull new files from server
6. Go to folder factorials and fix only the file with your name
7. Push corrections in master to server
8. Switch to myfixName and finish corrections in folder fibos
9. Push that branch to GitHub and issue a Pull Request to get
your branch merged
31/31