git - the basics

32
git

Transcript of git - the basics

git

without git

feature 1 feature 2 feature 3 feature 4 feature 5

final

project-v1project

without git

project-v2 project-v3 project-final

without git

?

setting up git

the basics

parts of a git repository

working directory

staging area (index)

git directory(HEAD)

stage commit

checkout

getting a git repository

git init

create one

git clone /path/to/repository

copy an existing repository

timeline

HEADmaster

timeline

HEADmaster

checking project status

git status file statuses

untracked

unmodified

modified

staged

tracking files / staging files

git add [filename]

git add [filename1] [filename2] [filename3]

git add . or git add *

untracked staged

modified staged

committing changes

git commit

git commit –m “commit message”

staged unmodified

timeline

HEADmaster

git work flow

create / delete / modify files

stage files

commit changes

[repeat]

git commit –am “commit message”

removing files

git rm [filename]

git rm [filename1] [filename2] [filename3]

removes the file from the staging area and the working directory

untracking files

git rm --cached [filename]

staged untracked

undoing things

git checkout -- [filename]

discarding changes

modified unmodified

git reset HEAD [filename]

unstaging files

git reset HEAD

staged modified

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

viewing changes

git diff

unstaged changes

git show [commit hash]

changes done in a commit

git diff --cached

staged changes

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”

branching

branching

timeline

HEAD

feature

master

git branch

list all branches

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]

committing to branches

timeline

master

HEAD

feature

git commit –m “commit message”

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

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

collaboration

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

two repositories

local repository- working directory- staging area- git directory

remote repository

- git directory

remotes

git remote

showing all remotes

git remote -v

include remote URL

managing remotes

git remote add [remote name] [remote URL]

creating a new remote

git remote rm [remote name]

deleting a remote

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

collaboration

end