Top Banner
git
32
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: git - the basics

git

Page 2: git - the basics

without git

feature 1 feature 2 feature 3 feature 4 feature 5

final

Page 3: git - the basics

project-v1project

without git

project-v2 project-v3 project-final

Page 4: git - the basics

without git

?

Page 5: git - the basics

setting up git

Page 6: git - the basics

the basics

Page 7: git - the basics

parts of a git repository

working directory

staging area (index)

git directory(HEAD)

stage commit

checkout

Page 8: git - the basics

getting a git repository

git init

create one

git clone /path/to/repository

copy an existing repository

timeline

HEADmaster

timeline

HEADmaster

Page 9: git - the basics

checking project status

git status file statuses

untracked

unmodified

modified

staged

Page 10: git - the basics

tracking files / staging files

git add [filename]

git add [filename1] [filename2] [filename3]

git add . or git add *

untracked staged

modified staged

Page 11: git - the basics

committing changes

git commit

git commit –m “commit message”

staged unmodified

timeline

HEADmaster

Page 12: git - the basics

git work flow

create / delete / modify files

stage files

commit changes

[repeat]

git commit –am “commit message”

Page 13: git - the basics

removing files

git rm [filename]

git rm [filename1] [filename2] [filename3]

removes the file from the staging area and the working directory

Page 14: git - the basics

untracking files

git rm --cached [filename]

staged untracked

Page 15: git - the basics

undoing things

git checkout -- [filename]

discarding changes

modified unmodified

git reset HEAD [filename]

unstaging files

git reset HEAD

staged modified

Page 16: git - the basics

undoing things

git commit --amend

changing the last commit

git reset --soft HEAD

undoing the last commit

unmodified staged

git reset --hard HEAD discard all changes in last commit

Page 17: git - the basics

viewing changes

git diff

unstaged changes

git show [commit hash]

changes done in a commit

git diff --cached

staged changes

Page 18: git - the basics

viewing commit history

git log

git log --oneline

git log --graph

git log --since=“2013-12-01”

git log --author=“Lorem Ipsum”

git log --until=“2013-12-01”

Page 19: git - the basics

branching

Page 20: git - the basics

branching

timeline

HEAD

feature

master

git branch

list all branches

Page 21: git - the basics

creating a branch

git branch [branch name] git checkout [branch-name]

switch to the new branch

timeline

HEAD

[branch name]

master timeline

HEAD

[branch name]

master

git checkout –b [branch name]

Page 22: git - the basics

committing to branches

timeline

master

HEAD

feature

git commit –m “commit message”

Page 23: git - the basics

merging branches

git checkout [branch to merge into]

switch to the branch you want to merge into

git merge [branch to merge from]

perform merge

Page 24: git - the basics

deleting a branch

git checkout [some other branch]

switch to a branch other than the one to be deleted

git branch –d [branch name]

delete branch

Page 25: git - the basics

collaboration

Page 26: git - the basics

setting up for Github

sign up for a Github account

generate SSH key (if your machine currently doesn’t have one)

add your SSH key to your Github account

Page 27: git - the basics

two repositories

local repository- working directory- staging area- git directory

remote repository

- git directory

Page 28: git - the basics

remotes

git remote

showing all remotes

git remote -v

include remote URL

Page 29: git - the basics

managing remotes

git remote add [remote name] [remote URL]

creating a new remote

git remote rm [remote name]

deleting a remote

Page 30: git - the basics

data transfer to/from a remote

git push [remote name] [remote branch name]

sending data to a remote

git pull [remote name] [remote branch name]

getting data from a remote

Page 31: git - the basics

collaboration

Page 32: git - the basics

end