0
GIT BASICSHow to quickly use Git for day to day developments...AND STASHLeverage Git on the EnterpriseCreated by /Original...
WHAT IS GIT ?DISTRIBUTED VERSION CONTROLSpeedSimpleNon Linear DevelopmentFully DistributedLarge Projects
SNAPSHOT BASED, NOT DELTASDIFFERENT FROMCVS,SVN...
GIT CONFIGURATION--system: /etc/gitconfig--global: ~/.gitconfigdefault: repo/.git/configCOLORS IN LINUX:gitconfig--globalu...
CREATION OF A REPONo need for networkCan do a lot locally on PCBest for testingGit init: repo + working directorygit init ...
EXAMPLE: FIRST COMMITmkdirgit-testsgitinitjohn.gitgitconfiguser.name"johnDoe"gitconfiguser.email"john@example.com"echo"fir...
ANOTHER COMMITcat>>file1SecondCommitfromJohngitcommit-a-m"anothercommit"
WORKING DIRECTORY, INDEXES ANDCOMMITS
VIEWING COMMITS HISTORY...lots of other options !!git blame: one files onlygitk: for graphic visualizationsame options as ...
COMMITS HISTORY (2)git show: details about a commit by default, shows the detailof the most recent commitgit show-branch: ...
VIEWING COMMIT DIFFERENCESgit diff: differences between the working directory and theindex--cached: between the index and ...
CANCELLATION, RESTORATION, CLEANINGgit reset: cancels changes about to be commited in theindex--hard: changes also the wor...
BRANCH MANAGEMENTA Branch is just a pointer to a commitnothing fancyvery lightweightvery similar to "tags"stored in .git/r...
BRANCH MANAGEMENT (2)git branch: list branches-r: remote branches as well-a all branchesgit branch dev: create branch "dev...
MERGINGgit merge dev:merges "dev" branch into current branchdoes not destroy "dev"git branch -d dev:deletes the "dev" bran...
CONFLICT RESOLUTIONgit merge can lead to conflicts if the same file has beenmodified in two branchesmanual conflict resolu...
REMOTE REPOSITORIESgit remote: lists all remote repos linked to the currentlocal repogit remote add name url: adds the spe...
REMOTES: FETCHING AND PULLINGThere is a separate copy of the remote commits separatedfrom the local branchCan be seen usin...
GIT REBASEWhen fetching commits from remote repos, there are twoways to merge them:regular merge: it will create a new com...
STASH: SAVE YOUR WORK WHILE SWITCHINGCONTEXTAllows to save your current context and switch workThen, you can restore the e...
STASH (2)warning, stashing does not store the branch stateThis means that you can recover your state on any branchpopping ...
GIT HOSTING IN THECOMPANYDifferent from git stash seen previously !!STASH
WHY NEED A GIT HOSTING TOOL?Git alone is not sufficientTo improve knowledge sharingto improve code visibilityto get the co...
STASH CARACTERISTICSStructuring projects, repos and rolesBrowse files, branches, commits and tagsCode Reviews concepts: Pu...
PROJECT STRUCTURESStash organized by projects that handles multiple repospermissions are based on projects and repos. Allo...
FILE BROWSINGCan browser any file and see source codeAllows to change branches and tagsCan have details of each commitbrow...
PULL REQUESTSImplements best practices with respect to code reviewAllows anyone to create a branch, make some code andask ...
FORKINGfork a repo into another repo, but keep historyallows for later merges
PRIVATE REPOSDevelop your own projectscan show or hide repos to others
JIRA LINKAllows to link Git commit to Jira issuesfrom a Jira issue, see all related commitswith Git hooks, you can force it
BRANCHING STRATEGIES WITH GITGit is small tool that does not come with a wholeenvironment and rules (think Clearcase...)Gi...
GIT FLOWStandard usages of branches when working with GitUsed in Big projects, with many developers working on it
MAIN CARACTERISTICS2 long lived branches : Develop and master3 short lived branches: Feature, Release and HotFixThe master...
STEPS TO FOLLOWCreate a Feature branch, name it to the story/feature youare working ononce you are happy with your feature...
STEPS TO FOLLOW (2)When a release must be done, use a temporary releasebranchThe Master branch is used only for "stable" v...
Upcoming SlideShare
Loading in...5
×

Git basics a starter on git and its ecosystem

1,490

Published on

Published in: Technology

Transcript of "Git basics a starter on git and its ecosystem"

  1. 1. GIT BASICSHow to quickly use Git for day to day developments...AND STASHLeverage Git on the EnterpriseCreated by /Original presentation onFrançois DAgostini @DagoFrancescoGitHub
  2. 2. WHAT IS GIT ?DISTRIBUTED VERSION CONTROLSpeedSimpleNon Linear DevelopmentFully DistributedLarge Projects
  3. 3. SNAPSHOT BASED, NOT DELTASDIFFERENT FROMCVS,SVN...
  4. 4. GIT CONFIGURATION--system: /etc/gitconfig--global: ~/.gitconfigdefault: repo/.git/configCOLORS IN LINUX:gitconfig--globaluser.name"FrançoisDAgostini"gitconfig--globaluser.email"fdagosti@nds.com"gitconfig--globalcolor.uialways
  5. 5. CREATION OF A REPONo need for networkCan do a lot locally on PCBest for testingGit init: repo + working directorygit init --bare: Repo onlygit clone:From an existing repo
  6. 6. EXAMPLE: FIRST COMMITmkdirgit-testsgitinitjohn.gitgitconfiguser.name"johnDoe"gitconfiguser.email"john@example.com"echo"firstlinefromJohn">file1gitaddfile1gitstatusgitcommit-m"initialcommitfromJohn"
  7. 7. ANOTHER COMMITcat>>file1SecondCommitfromJohngitcommit-a-m"anothercommit"
  8. 8. WORKING DIRECTORY, INDEXES ANDCOMMITS
  9. 9. VIEWING COMMITS HISTORY...lots of other options !!git blame: one files onlygitk: for graphic visualizationsame options as git loggitlog--decorate--graph--stat--oneline-n
  10. 10. COMMITS HISTORY (2)git show: details about a commit by default, shows the detailof the most recent commitgit show-branch: show details about the current branchHANDY ALIASgitconfig--globalalias.graph"log--decorate--graph--oneline"
  11. 11. VIEWING COMMIT DIFFERENCESgit diff: differences between the working directory and theindex--cached: between the index and the most recent commitHEAD: between the working directory and the most recentcommit
  12. 12. CANCELLATION, RESTORATION, CLEANINGgit reset: cancels changes about to be commited in theindex--hard: changes also the working directorygit checkout: cancels changes made to working directorycompared to indexgit clean: deletes files not followed by Git.-f option to really delete them-n to simulate.gitignore file: to avoid Git to track useless files
  13. 13. BRANCH MANAGEMENTA Branch is just a pointer to a commitnothing fancyvery lightweightvery similar to "tags"stored in .git/refs/[heads|remotes|tags]Default branch name: master
  14. 14. BRANCH MANAGEMENT (2)git branch: list branches-r: remote branches as well-a all branchesgit branch dev: create branch "dev"Does not change the current branchgit checkout dev: move the current branch to the "dev"branch-b: create the branch while switching to it
  15. 15. MERGINGgit merge dev:merges "dev" branch into current branchdoes not destroy "dev"git branch -d dev:deletes the "dev" branchonly deletes the pointercan be deleted only if the branch is accessible from thecurrent branchThis is usually what is needed after merging. The old"dev" pointer is no longer usefulin case of future branching, a new branch can becreated
  16. 16. CONFLICT RESOLUTIONgit merge can lead to conflicts if the same file has beenmodified in two branchesmanual conflict resolution is needed on this filesconflict markers are added by git and need to be removedby the developpergit add on the conflict filesgit commit to end the mergeand of course, delete the merged branchif conflict resolution is too complex:git merge --abort: restores the working directory to thestate it was prior to merge
  17. 17. REMOTE REPOSITORIESgit remote: lists all remote repos linked to the currentlocal repogit remote add name url: adds the specified url as aremote repo to the local repoNo need in case repo has been created with git clonegit push repo: push local commits on the current branch tothe same branch on the remote repowarning: the remote repo must already have the samebranch, else use git push repo branch
  18. 18. REMOTES: FETCHING AND PULLINGThere is a separate copy of the remote commits separatedfrom the local branchCan be seen using git branch -athis means that the remote and the local copy can easilybe comparedgit fetch repo: updates the local copy of the remote repogit pull: like git fetch, but also merges the remote commitinto this repos branchthis one can lead to conflicts
  19. 19. GIT REBASEWhen fetching commits from remote repos, there are twoways to merge them:regular merge: it will create a new commit every timerebase: it will not create a new commitallows to change the commits that were not published tohave new parentsvery handy when you need to integrate other peoplechanges but continu your workuse: git rebase branchgit pull --rebase: will use the reboase algorithm in case ofconflicts instead of merge
  20. 20. STASH: SAVE YOUR WORK WHILE SWITCHINGCONTEXTAllows to save your current context and switch workThen, you can restore the exact state backgit stash save messages: stores the working director andthe index into a stackgit stash list: lists all the saved stacksgit stash show: shows the details of a stack itemgit stash pop: pops a state and applies it on the currentworking directorygit stash drop: removes an item on the stack
  21. 21. STASH (2)warning, stashing does not store the branch stateThis means that you can recover your state on any branchpopping a state can create conflicts that needs to bemergedif a pop failed because of a conflict, it will need to beremoved manually
  22. 22. GIT HOSTING IN THECOMPANYDifferent from git stash seen previously !!STASH
  23. 23. WHY NEED A GIT HOSTING TOOL?Git alone is not sufficientTo improve knowledge sharingto improve code visibilityto get the code out of the darkness !!
  24. 24. STASH CARACTERISTICSStructuring projects, repos and rolesBrowse files, branches, commits and tagsCode Reviews concepts: Pull requestsRepos forkingprivate reposJira linking
  25. 25. PROJECT STRUCTURESStash organized by projects that handles multiple repospermissions are based on projects and repos. Allows fordecentralized adminusers have roles: project creators, admins, system admins,writerSoon, anonymous mode
  26. 26. FILE BROWSINGCan browser any file and see source codeAllows to change branches and tagsCan have details of each commitbrowse list of commits and logmarkdown support to explain source code organization
  27. 27. PULL REQUESTSImplements best practices with respect to code reviewAllows anyone to create a branch, make some code andask for its mergeBranch permissions allows to control commitsPull requests allow to review, make comments, ammendnew commits, see diffs...Anyone can watch a pull request and be notifiedPull requests can be declined or accepted
  28. 28. FORKINGfork a repo into another repo, but keep historyallows for later merges
  29. 29. PRIVATE REPOSDevelop your own projectscan show or hide repos to others
  30. 30. JIRA LINKAllows to link Git commit to Jira issuesfrom a Jira issue, see all related commitswith Git hooks, you can force it
  31. 31. BRANCHING STRATEGIES WITH GITGit is small tool that does not come with a wholeenvironment and rules (think Clearcase...)Git is versatile and can be used in a dozen of differentwaysGit itself does not enforce how to use branches and howto work as a team. It keeps this openBut how a serious company is supposed to use git for all itsprojects without going messy ?WENEED BEST PRACTICES !!
  32. 32. GIT FLOWStandard usages of branches when working with GitUsed in Big projects, with many developers working on it
  33. 33. MAIN CARACTERISTICS2 long lived branches : Develop and master3 short lived branches: Feature, Release and HotFixThe master branch is restricted to commit by one or twopeopleThe Develop branch is restricted to senior developersNew code is added through Feature branches only
  34. 34. STEPS TO FOLLOWCreate a Feature branch, name it to the story/feature youare working ononce you are happy with your features, you create a pullrequest to merge it
  35. 35. STEPS TO FOLLOW (2)When a release must be done, use a temporary releasebranchThe Master branch is used only for "stable" versioncommits. Any commits on master should have a TagIf a bug is found on Master, a "HotFix branch is created tocorrect it and merge it back on master
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×