Your SlideShare is downloading. ×
Git basics  a starter on git and its ecosystem
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Git basics a starter on git and its ecosystem


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 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. WHAT IS GIT ?DISTRIBUTED VERSION CONTROLSpeedSimpleNon Linear DevelopmentFully DistributedLarge Projects
  • 4. GIT CONFIGURATION--system: /etc/gitconfig--global: ~/.gitconfigdefault: repo/.git/configCOLORS IN"FrançoisDAgostini"""gitconfig--globalcolor.uialways
  • 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. EXAMPLE: FIRST"johnDoe"""echo"firstlinefromJohn">file1gitaddfile1gitstatusgitcommit-m"initialcommitfromJohn"
  • 7. ANOTHER COMMITcat>>file1SecondCommitfromJohngitcommit-a-m"anothercommit"
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. GIT HOSTING IN THECOMPANYDifferent from git stash seen previously !!STASH
  • 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. STASH CARACTERISTICSStructuring projects, repos and rolesBrowse files, branches, commits and tagsCode Reviews concepts: Pull requestsRepos forkingprivate reposJira linking
  • 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. 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. 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. FORKINGfork a repo into another repo, but keep historyallows for later merges
  • 29. PRIVATE REPOSDevelop your own projectscan show or hide repos to others
  • 30. JIRA LINKAllows to link Git commit to Jira issuesfrom a Jira issue, see all related commitswith Git hooks, you can force it
  • 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. GIT FLOWStandard usages of branches when working with GitUsed in Big projects, with many developers working on it
  • 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. 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. 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