Sei sulla pagina 1di 14

1/8/2015

git - the simple guide - no deep shit!

git - the simple guide


justasimpleguideforgettingstartedwithgit.nodeepshit)
Tweet

4,747

byRogerDudler
creditsto@tfnico,@fhdandNamics
thisguideindeutsch,espaol,franais,italiano,nederlands,portugus,,trke,
,,,Vietnamese
pleasereportissuesongithub

setup
DownloadgitforOSX
DownloadgitforWindows
http://rogerdudler.github.io/git-guide/

1/14

1/8/2015

git - the simple guide - no deep shit!

DownloadgitforLinux

create a new repository


createanewdirectory,openitandperforma
git init
tocreateanewgitrepository.

checkout a repository
createaworkingcopyofalocalrepositorybyrunningthecommand
git clone /path/to/repository
whenusingaremoteserver,yourcommandwillbe
git clone username@host:/path/to/repository

http://rogerdudler.github.io/git-guide/

2/14

1/8/2015

git - the simple guide - no deep shit!

workflow
yourlocalrepositoryconsistsofthree"trees"maintainedbygit.thefirstoneis
your Working Directory whichholdstheactualfiles.thesecondoneis
the Index whichactsasastagingareaandfinallythe HEAD whichpoints
tothelastcommityou'vemade.

add & commit


Youcanproposechanges(addittotheIndex)using
git add <filename>
git add *
Thisisthefirststepinthebasicgitworkflow.Toactuallycommitthese

http://rogerdudler.github.io/git-guide/

3/14

1/8/2015

git - the simple guide - no deep shit!

changesuse
git commit -m "Commit message"
NowthefileiscommittedtotheHEAD,butnotinyourremoterepositoryyet.

pushing changes
YourchangesarenowintheHEADofyourlocalworkingcopy.Tosendthose
changestoyourremoterepository,execute
git push origin master
Changemastertowhateverbranchyouwanttopushyourchangesto.

Ifyouhavenotclonedanexistingrepositoryandwanttoconnectyour
repositorytoaremoteserver,youneedtoadditwith
git remote add origin <server>
Nowyouareabletopushyourchangestotheselectedremoteserver

branching
http://rogerdudler.github.io/git-guide/

4/14

1/8/2015

git - the simple guide - no deep shit!

Branchesareusedtodevelopfeaturesisolatedfromeachother.Themaster
branchisthe"default"branchwhenyoucreatearepository.Useotherbranches
fordevelopmentandmergethembacktothemasterbranchuponcompletion.

createanewbranchnamed"feature_x"andswitchtoitusing
git checkout -b feature_x
switchbacktomaster
git checkout master
anddeletethebranchagain
git branch -d feature_x
abranchisnotavailabletoothersunlessyoupushthebranchtoyourremote
repository
git push origin <branch>

http://rogerdudler.github.io/git-guide/

5/14

1/8/2015

git - the simple guide - no deep shit!

update & merge


toupdateyourlocalrepositorytothenewestcommit,execute
git pull
inyourworkingdirectorytofetchandmergeremotechanges.
tomergeanotherbranchintoyouractivebranch(e.g.master),use
git merge <branch>
inbothcasesgittriestoautomergechanges.Unfortunately,thisisnotalways
possibleandresultsinconflicts.Youareresponsibletomergethoseconflicts
manuallybyeditingthefilesshownbygit.Afterchanging,youneedtomark
themasmergedwith
git add <filename>
beforemergingchanges,youcanalsopreviewthembyusing
git diff <source_branch> <target_branch>

tagging
it'srecommendedtocreatetagsforsoftwarereleases.thisisaknownconcept,
whichalsoexistsinSVN.Youcancreateanewtagnamed1.0.0byexecuting
http://rogerdudler.github.io/git-guide/

6/14

1/8/2015

git - the simple guide - no deep shit!

git tag 1.0.0 1b2e1d63ff


the1b2e1d63ffstandsforthefirst10charactersofthecommitidyouwantto
referencewithyourtag.Youcangetthecommitidbylookingatthe...

log
initssimplestform,youcanstudyrepositoryhistoryusing.. git log
Youcanaddalotofparameterstomaketheloglooklikewhatyouwant.To
seeonlythecommitsofacertainauthor:
git log --author=bob
Toseeaverycompressedlogwhereeachcommitisoneline:
git log --pretty=oneline
OrmabeyouwanttoseeanASCIIarttreeofallthebranches,decoratedwith
thenamesoftagsandbranches:
git log --graph --oneline --decorate --all
Seeonlywhichfileshavechanged:
git log --name-status
Thesearejustafewofthepossibleparametersyoucanuse.Formore,see
git log --help

http://rogerdudler.github.io/git-guide/

7/14

1/8/2015

git - the simple guide - no deep shit!

replace local changes


Incaseyoudidsomethingwrong(whichforsureneverhappens)youcan
replacelocalchangesusingthecommand
git checkout -- <filename>
thisreplacesthechangesinyourworkingtreewiththelastcontentinHEAD.
Changesalreadyaddedtotheindex,aswellasnewfiles,willbekept.
Ifyouinsteadwanttodropallyourlocalchangesandcommits,fetchthelatest
historyfromtheserverandpointyourlocalmasterbranchatitlikethis
git fetch origin
git reset --hard origin/master

useful hints
builtingitGUI
gitk
usecolorfulgitoutput
git config color.ui true
http://rogerdudler.github.io/git-guide/

8/14

1/8/2015

git - the simple guide - no deep shit!

showlogonjustonelinepercommit
git config format.pretty oneline
useinteractiveadding
git add -i

links & resources


graphicalclients
GitX(L)(OSX,opensource)
Tower(OSX)
SourceTree(OSX&Windows,free)
GitHubforMac(OSX,free)
GitBox(OSX,AppStore)

guides
GitCommunityBook
ProGit
Thinklikeagit
GitHubHelp
AVisualGitGuide

gethelp
GitUserMailingList
#gitonirc.freenode.net

http://rogerdudler.github.io/git-guide/

9/14

1/8/2015

git - the simple guide - no deep shit!

comments
374Comments

gitthesimpleguide

Login

Share Favorite

SortbyNewest

Jointhediscussion
rcn 5daysago

somaybeI'mmisuderstandinggit..butIhaveaworkingdirectorywithonefileinit,andI
madeabranchnamed"develop"tomodifythatfilewhichinvolvedbreakingitfor
awhile.however,IjustrealizedthatifIgitcheckoutbetweenmymasteranddevelop
branch,thatfileisexactlythesameinbothbranches,iewhat'sthepointofmakinga
separatebranchtotestchangesinifit'smodifyingthefileinmymasterbranchaswell?
wassurprisedthathappened,maybeI'mdoingsomethingwrong?

Reply Share

SeijiNaganuma>rcn 4daysago

ThewayIlookatbranchesisthattheyarepointerstocommitsorsnapshotsyou
havemade.Whenyoucreateandcheckoutthenewbranch,you'reonlygoingto
movethe"develop"pointerforward.Onceyoucheckoutthemasterbranch,
you'removingthe"master"pointereachtimeyoumakeacommit.
Tomakethemasteranddevelopbranchestheexactsameyoueitherhadtohave
mergedthetwobranchestogetherormistakenlymadechangesonthewrong
branch.
Oneimportantpointtorememberisthatcreatinganewbranchdoesn't
automaticallycheckoutthatbranch.Youneedtorun"gitbranchdevelop"then
"gitcheckoutdevelop"orrun"gitcheckoutbdevelop".

Reply Share

rcn>SeijiNaganuma 4daysago

maybeIaccidentallydiditwithoutcheckingouttoadifferentbranch,I'm
notsure.So,ifI'minmyworkingdirectory(thelocalfolderonmyactual
computer)whereIinitializedgit,andIgitcheckouttoanewbranch,then
Iopenandeditmyfile(inthenewbranch)inmytexteditor,saveitand
exitout..howdoesgittelltheactuallocalfilethatit'ssupposedtohave
twoinstances?(ontwoseparatebranches).Inthatscenario,theonlyfile
thatshouldhavethechangesistheonethat'sinthebranchIeditedit
from,correct?

Reply Share

SeijiNaganuma>rcn 3daysago

theworkingdirectorywilllooklikeyourbranchthatyou
checkout.SoifyoudoworkonDevelopandthencheckout
Master,yourworkingdirectorywillchange.Gitwillmakesure
thatthereisnouncommittedchangesbeforeyoucheckouta
differentbranch.Theinformationforthedifferentbranchesare
storedinyou.gitfolder.

Reply Share

MeteorFury 6daysago

Yeah,thisisexactlywhatIneeded.Goodbasictutorial.

Reply Share

UmerJafer 9daysago

http://rogerdudler.github.io/git-guide/

10/14

1/8/2015

git - the simple guide - no deep shit!

GreatTutorial!BestforanyonecomingfromSVNorsomeotherrepowhodon'tneedno
deepshit)
1

Reply Share

sidn 14daysago

Awesometutorial!Thanksalot!:)
3

Reply Share

lmayorga 18daysago

Sorryaboutthatnewtosocialmediaofanysort.Apparentlyneedtoworkondragging
anddropping.
1

Reply Share

lmayorga 18daysago

I'mforeverinyourdebtforprovidingabigpicturecontextformyisolatedinsights!

Reply Share

JAYTECH 20daysago

SuperHelpful!Thankyousomuch!
1

Reply Share

TomasDrozda 22daysago

Awesome:)

Reply Share

fasflow 22daysago

Thanksalotforthistuto/memoofgit!Iloveit!!Andwhataflatdesignwebsite!
*APPLAUSE*

Reply Share

thekngmkr 22daysago

Dude...justmademyday...nodeepshit...haha
3

Reply Share

MattRhysDavies 22daysago

Absolutelybrilliantthankyou.WishIhadfoundthisguidewhenIwasfirststartingout
withGit!
3

Reply Share

AndyHidayat 24daysago

awesometutorials...great!!!!

Reply Share

NickJacobs 25daysago

So,so,sohelpful.Gitisoneofthosetoolswhereeverythingisfamiliarandyetdifferent
atthesametime.Thanks!

Reply Share

akyan amonthago

reallyhelpful!Thanks!

Reply Share

NeoIndia amonthago

Best!Youproveditthingscanbesimpleandgreat!
Cheers,
Neo
http://rogerdudler.github.io/git-guide/

11/14

1/8/2015

git - the simple guide - no deep shit!

Neo

Reply Share

Haren amonthago

Itisreallyhelpful.....alreadybookmarkedthispage.

Reply Share

Jin amonthago

hi!ijustwanttoaskwhatifitisaskingmetostashmychanges?whatshouldido?
thanks!
2

Reply Share

VineethReddy>Jin amonthago

canyoubespecificwhengitaskedyoutostashyourchanges.
Ingeneral,stashingby"gitstash"removesallchangesfromstagingareaand
modifiedareaandaresavedit.gitfolder.You'llthenhaveacleanslatewithout
anychanges.Youneednotworryaboutallyourchanges,youcanreapplythem
using"gitstashapply"
1

Reply Share

LudovicHenin amonthago

Yourcommentslistisinsanebud.
Butwhatanawesomepage.Thanks.

Reply Share

nihat amonthago

awesometutorial,thanks!

Reply Share

AllenStroy amonthago

Loveit!Greatsimpleoverview!!!

Reply Share

PhmSinh amonthago

thanksyou!great
1

Reply Share

IvanLozo amonthago

great,thankyou!

Reply Share

JooCarlosFerreira amonthago

Thisisreallyhelpful!
Thanksforthepost

Reply Share

ShonFeder amonthago

thankyou!Iwillbereferringbackoften.
1

Reply Share

TweetsOfSumit amonthago

ha!Goodstuff,thanks!

Reply Share

berkapavel amonthago

reallyhelpful...thankyou

Reply Share

ashwin amonthago

thankssssssss

Reply Share

JoeDougherty amonthago

Greatguide.I'vebeenontheperipheralofgitforalongtime,nowIneeditandthis
makesalotclear.Greatsite,andthanks.
http://rogerdudler.github.io/git-guide/

12/14

1/8/2015

git - the simple guide - no deep shit!


makesalotclear.Greatsite,andthanks.

Reply Share

RocoGarcaLuque amonthago

Precious:)

Reply Share

JerryMarshall 2monthsago

greatguide,thanks!!

Reply Share

pshinoj 2monthsago

ThisisreallyusefulforGitHubstarters!Thanks

Reply Share

RajeshMule 2monthsago

Hi,IhavecreatedanAndroidappbasedonthiswebsitethatworksofflineandhasallthe
awesomenessofthewebsite.Hopeithelpsmorepeople.Happylearning:)
https://play.google.com/store/...
2

Reply Share

DmitriyUsakov 2monthsago

oneofthebesttutorialforbeginner!Thanks

Reply Share

JiriDanecek 2monthsago

IhavereadalotofstuffaboutgitbutforthefirsttimeIknowhowtouseit

Reply Share

DWisehart 2monthsago

'gitstatus'isanotherbasiclevelcommandthatwouldbegoodtolist.Easiertoremember
than'gitcommitdryrun'.

Reply Share

Uday 2monthsago

Awesome,thanksaton:)

Reply Share

saeedraeesmohammadi 2monthsago

Thanksalot!

Reply Share

JinalKothari 2monthsago

Thanksaton!!Thisissuperhelpful!!!!!!

Reply Share

DanielGarcaPez 2monthsago

Theperfectguide!

Reply Share

NicholasLawson 2monthsago

JustwhatIwaslookingfor.

Reply Share

Deepak 2monthsago

Indeedasimple,helpful&amazingguide!!
Thanksforyoureffortsforputtingupsuchauseful&concisetutorial

Reply Share

Bob 2monthsago

Bestguideever,itnowallmakessensethankssomuch!

Reply Share

William 2monthsago

Greatguide!
http://rogerdudler.github.io/git-guide/

13/14

1/8/2015

git - the simple guide - no deep shit!

Reply Share

JohnZhao 2monthsago

Greatestguideforbeginners!

Reply Share

AndriiKuplevakhskyi 2monthsago

HelloRoger,
manythanksforsuchaguide!Itseemstobeveryusefulfornewbies.
I'dliketotranslatetheguideintoUkrainian.I'lltryyoplaywiththesourcesonGitHubto
doit.We'llseehowitgoes.
Please,letmeknowifyouhaveanythoughts/objections.
Cheers,

Reply Share

mahdi 2monthsago

Thankssomuch

Reply Share

Loadmorecomments

WHAT'STHIS?

ALSOONGITTHESIMPLEGUIDE

gitguiaprticosemcomplicao!

git

73comments2yearsago

5commentsamonthago

PrapathNuiSuayroop

BrunoBarcellosEsselivro


Text

distribudogratuitamenteatravsdalicena
CreativeCommons,logono

git!
1comment2yearsago

dsssssssswhatagoodsite

gitDereinfacheEinstiegkein
Schnickschnack!
33comments2yearsago

tkHatmirsehrgeholfen.Danke!

Subscribe

http://rogerdudler.github.io/git-guide/

AddDisqustoyoursite

Privacy

14/14

Potrebbero piacerti anche