Share
Embed
A brief introduction to git and Github
This presentation covers an introduction to distributed version control systems, moves on to explain the basics of git: how to track files, perform commits and fix merge conflicts. Finally, it provides links to different distributed workflows and focuses on the Central repository workflow. All of this is explained to work at the command line level but links to graphical interfaces are provided at the end of the presentation, together with some other useful resources.
Kiko
March 31, 2016
Transcript
85 slides
-
Distributed Version Control System • Remote and local copies •
Keep track of file changes • Knows what you did last summer • Remembers authorship Git: 2 -
Distributed Version Control System • Remote and local copies •
Keep track of file changes • Knows what you did last summer • Remembers authorship Git: 2 -
Distributed Version Control System • Remote and local copies •
Keep track of file changes • Knows what you did last summer • Remembers authorship Git: 2 -
Distributed Version Control System • Remote and local copies •
Keep track of file changes • Knows what you did last summer • Remembers authorship Git: 2 -
Github & Git • Set up an account • Create
a repository (repo) • Add things to your repo • Branch workflow • Share changes with your team 3 -
• Create Github account • Set up Git (link Github)
5 Linux & OS X $ git config --global push.default simple $ git config --global core.editor “subl -n -w” link config editors -
• Create Github account • Set up Git (link Github)
5 Windows $ git config --global push.default simple $ git config --global core.editor “subl -n -w” link config editors -
Create a repository (repo) Add collaborators to repo Clone repo
on local machine $ git clone https://github.com/kikofernandez/git-intro.git $ git clone <address-repo> Remote Remote Local = the remote server, Github = your local machine Local Initial Steps: Remote -
Create a repository (repo) Add collaborators to repo Clone repo
on local machine $ git clone https://github.com/kikofernandez/git-intro.git Remote Remote Local = the remote server, Github = your local machine Local Initial Steps: Remote -
Git: Basics 7 Holds actual files Which files form commit
Commits Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> Changes that make up a commit Commands: $ git commit -m “message” Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md Changes that make up a commit Commands: $ git commit -m “message” Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md this is an introduction to the course … intro.md Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md this is an introduction to the course … intro.md Local -
Git: Basics 8 Working Directory Staging Area Folder of your
repository, e.g. ~/git-intro Commands: $ git add <file> this is an introduction to the course … intro.md $ git add intro.md Changes that make up a commit Commands: $ git commit -m “message” $ git commit -m “add intro.md file” this is an introduction to the course … intro.md this is an introduction to the course … intro.md Local -
Git: Logs 9 $ git log -p How do I
see the changes? Remote Local -
Git: Logs 9 $ git log -p How do I
see the changes? Remote Local -
Git: Logs 9 $ git log -p How do I
see the changes? Remote Local -
Git: Logs 9 $ git log -p How do I
see the changes? Remote Local -
Commit early, commit often A tip for version controlling -
not for relationships ( ) 10 Best tip you will ever receive: -
Git: Branching Local 3ddf4 master Branches: they are pointers to
commits / versions Default branch: master $ git add intro.md; git commit -m “update” 12 -
Git: Branching Local 3ddf4 master Branches: they are pointers to
commits / versions Default branch: master $ git add intro.md; git commit -m “update” 12ab56 12 -
Git: Branching Local 3ddf4 master Branches: they are pointers to
commits / versions Default branch: master $ git add intro.md; git commit -m “update” 12ab56 3eee8 12 -
Git: Branching Local 3ddf4 master Branches: they are pointers to
commits / versions Default branch: master 13 -
Git: Branching Local 3ddf4 master Branches: they are pointers to
commits / versions Default branch: master $ git branch frontend frontend 13 -
Git: Branching Local 3ddf4 HEAD master Branches: they are pointers
to commits / versions Default branch: master $ git branch frontend frontend HEAD: pointer to the current branch 13 -
Git: Branching Local 3ddf4 HEAD master Branches: they are pointers
to commits / versions Default branch: master $ git branch frontend frontend HEAD: pointer to the current branch $ git checkout frontend 13 -
Git: Branching Local 3ddf4 HEAD Branches: they are pointers to
commits / versions Default branch: master $ git branch frontend HEAD: pointer to the current branch $ git checkout frontend master frontend 13 -
Git: Branching Local 3ddf4 HEAD Branches: they are pointers to
commits / versions Default branch: master $ git branch frontend 12ab56 HEAD: pointer to the current branch $ git checkout frontend master frontend $ git commit -a -m “commit everything” 13 -
Git: Branching Local 3ddf4 HEAD Branches: they are pointers to
commits / versions Default branch: master $ git branch frontend 12ab56 3eee8 HEAD: pointer to the current branch $ git checkout frontend master frontend $ git commit -a -m “commit everything” 13 -
Git: Branching Local 3ddf4 HEAD Branches: they are pointers to
commits / versions Default branch: master 12ab56 3eee8 HEAD: pointer to the current branch master frontend 14 -
Git: Branching Local 3ddf4 HEAD Branches: they are pointers to
commits / versions Default branch: master $ git checkout master 12ab56 3eee8 HEAD: pointer to the current branch master frontend 14 -
Git: Branching Local 3ddf4 HEAD master Branches: they are pointers
to commits / versions Default branch: master $ git checkout master frontend 12ab56 3eee8 HEAD: pointer to the current branch 14 -
Git: Branching Local 3ddf4 HEAD master How to merge master
with the changes in frontend? $ git merge frontend frontend 12ab56 3eee8 HEAD: pointer to the current branch 15 -
Git: Branching Local 3ddf4 HEAD master How to merge master
with the changes in frontend? $ git merge frontend frontend 12ab56 3eee8 HEAD: pointer to the current branch 15 -
+ Test test + This is my first line Git:
Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 HEAD master Commits: 12ab56 and 3eee8 add a line in same file -
+ Test test + This is my first line Git:
Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Commits: 12ab56 and 3eee8 add a line in same file -
+ Test test + This is my first line Git:
Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file -
+ Test test + This is my first line Git:
Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file -
+ Test test + This is my first line Git:
Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file -
+ Test test + This is my first line Git:
Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file -
+ Test test + This is my first line Git:
Conflicts Local 3ddf4 $ git merge frontend frontend 12ab56 3eee8 17 6664f HEAD master Conflicts: 12ab56 and 3eee8 update same line Commits: 12ab56 and 3eee8 add a line in same file -
Git conflicts: Recipe $ git add <name-of-files-with-conflicts> $ git commit
When you get conflicts: 1. fix the conflicts 2. 3. -
Github ❤ Git • So far, your changes are in
local computer • Problem: What if you drop the computer? Work in Teams? 20 -
Github ❤ Git • So far, your changes are in
local computer • Problem: What if you drop the computer? Work in Teams? • Solution: Github saves your work in the “cloud” 20 -
Github ❤ Git • Push your local changes to your
remote repository $ git push origin master Name of the remote url: by default, it’s always called origin Name of your branch: your initial branch is always called master 21 Remote $ git remote -v -
Github ❤ Git • Pull remote changes to your local
repository $ git pull origin master Name of the remote url: by default, it’s always called origin Name of the local branch to pull into: your initial branch is always called master 22 Remote $ git remote -v -
3ddf4 HEAD master The remote end is similar to a
branch $ git commit -am “commit everything” origin/master HEAD: pointer to the current branch 23 Github ❤ Git Remote -
3ddf4 HEAD master The remote end is similar to a
branch $ git commit -am “commit everything” origin/master 12ab56 HEAD: pointer to the current branch 23 Github ❤ Git Remote -
3ddf4 HEAD master The remote end is similar to a
branch $ git commit -am “commit everything” origin/master 12ab56 3eee8 HEAD: pointer to the current branch 23 Github ❤ Git Remote -
3ddf4 HEAD master The remote end is similar to a
branch $ git commit -am “commit everything” origin/master 12ab56 3eee8 HEAD: pointer to the current branch 23 Github ❤ Git Remote $ git push origin master -
3ddf4 HEAD master The remote end is similar to a
branch $ git commit -am “commit everything” origin/master 12ab56 3eee8 HEAD: pointer to the current branch 23 Github ❤ Git Remote $ git push origin master -
Distributed Recipes • Centralised Workflow • Integration-Manager Workflow • Dictator-Lieutenants
Workflow *recipes = workflow -
Distributed Recipes • Centralised Workflow • Integration-Manager Workflow • Dictator-Lieutenants
Workflow *recipes = workflow -
Centralised recipe $ git pull origin master Easy start: everyone
works on the same branch $ git add <files> Do some work $ git commit -m “<message>” $ git push origin master rinse and repeat Works until you get conflicts -
3ddf4 HEAD master 26 Conflicts in Centralised recipe @kikofernandez 3ddf4
origin/master Github 3ddf4 HEAD master origin/master origin/master @kikofernandez @supercooldave @supercooldave -
3ddf4 HEAD master 26 Conflicts in Centralised recipe @kikofernandez 3ddf4
origin/master Github 3ddf4 HEAD master origin/master origin/master $ git commit -am “stuff” @kikofernandez @supercooldave @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master origin/master origin/master $ git commit -am “stuff” @kikofernandez @supercooldave @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master origin/master origin/master $ git commit -am “stuff” $ git commit -am “work” @kikofernandez @supercooldave @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git commit -am “stuff” $ git commit -am “work” @kikofernandez @supercooldave @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” @kikofernandez @supercooldave @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” 12ab56 @kikofernandez @supercooldave @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave @supercooldave error: failed to push some refs to '/path/to/repo.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave $ git pull origin master @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave $ git pull origin master 12ab56 87abe @supercooldave -
3ddf4 HEAD master 12ab56 26 Conflicts in Centralised recipe @kikofernandez
3ddf4 origin/master Github 3ddf4 HEAD master 3eba4 origin/master origin/master $ git push origin master $ git commit -am “stuff” $ git commit -am “work” $ git push origin master 12ab56 @kikofernandez @supercooldave $ git pull origin master 87abe $ git push origin master 12ab56 87abe 3eba4 @supercooldave -
Useful links • Conflict example (for you to practice) •
Git - the simple guide • Github: Bootcamp • Git: Cheatsheet • Learn enough git to be dangerous • CodeSchool: Try git 27 -
Summary Introduction to git and Github & Distributed workflows so…
let’s git some fun