Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's git started

Let's git started

Git workshop for beginners.
#git #workshop #devconph #devcondavao

July 15, 2017 @ Ingenuity HQ

Renemari Padillo

July 15, 2017
Tweet

More Decks by Renemari Padillo

Other Decks in Technology

Transcript

  1. By the end of this workshop you will... • Have

    basic knowledge what is version control • Have basic understanding what is git • Learn how to use git on your projects
  2. What is Git? Git is a postmodern version control system

    used by the world today. It’s a mature and actively maintained open-source project originally developed by Linus Torvalds (The creator of Linux) in 2005.
  3. Initial commit Implemented login feature Merged changes from dev Fixed

    typo on login page Merged changes from dev Merged changes from staging Timeline Version Control Surprise popup notification A (discontinued) Alpha release master staging dev tag
  4. Setting up Git Establish your credential git config --global user.name

    “<YOUR-NAME-HERE>” git config --global user.email “<YOUR-EMAIL-HERE>” git config --global color.ui “auto”
  5. Working with git OR clone from existing projects hosted from

    elsewhere git clone <repository-url-here>
  6. Tracked Files Staged Files Untracked .git Let’s start by adding

    a file. Do the command: touch README.md G IT Understanding commit status
  7. Understanding commit status Tracked Files Staged Files Untracked .git README.md

    Any added or changed file(s) will be marked as untracked. Do the command: git status G IT
  8. Understanding commit status Tracked Files Staged Files Untracked .git README.md

    To be able to commit the change, we must move to change to staged files Do the command: git add README.md G IT
  9. Understanding commit status Tracked Files Staged Files Untracked .git README.md

    Do the command: git status The status of the file is now on staged files and will be marked as a new file G IT
  10. Understanding commit status Tracked Files Staged Files Untracked .git README.md

    Once there is/are staged file(s) you can now commit your work. Do the command: git commit -m “Added README” G IT
  11. Understanding commit status Tracked Files Staged Files Untracked .git README.md

    Do the command: git status The changes are now committed and will be added to the tracked files. G IT
  12. Commit Hashes All commits are recorded and have a unique

    ID. Rather than a sequential revision ID, Git marks each commit with a SHA-1 hash that is unique to the person committing the changes, the folders, and the files comprising the changeset. 64de179becc3ed324daab72f7238df1404723672
  13. Commit Log View the commit history git log (Prettify) git

    log --oneline --graph --abbrev-commit --decorate
  14. Branching Branching superficially appears much the same as it does

    in other version control systems, but the difference lies in the fact that git branches can be targeted to exist only locally, or be shared with (pushed to) the rest of the team. M D T F F
  15. Branches To create a branch execute the following command. git

    branch <new branch name> <from branch> git branch <new branch name>
  16. Branches Once you have created a branch, you can check

    out (switch to) a branch by simply executing the following command: git checkout <branch name> (Create branch then switch) git checkout -b <new branch name>
  17. Merge Like other popular VCSs, Git allows you to merge

    one or more branches into the current branch. git merge <branch one> git merge <branch one> <branch two>
  18. Understanding git merge A C C 1 D B master

    feat On this scenario, a feature branch is being merge to master.
  19. Understanding git merge A C C 1 D B E

    master feat When both branches are merged, this is how your git history looks like.
  20. Understanding git merge A C C 1 D B E

    master feat The green circle represents the merge commit created automatically after git merge
  21. Rebase Rebasing is the rewinding of existing commits on a

    branch with the intent of moving the “branch start point” forward, then replaying the rewound commits. git rebase <source branch> git rebase <source branch> <destination branch>
  22. Rebasing commits A C C 1 D B master feat

    The same scenario, but we use git rebase
  23. Rebasing commits A C C 1 D B master feat

    D This is how it looks like after you rebase the feature branch
  24. Rebasing commits A C C 1 D B master feat

    D When you rebase a branch, it does not create a merge commit but instead it fast forward to the latest commit
  25. Rebasing commits Every time you add and rebase commits it

    does not clutter the git history of the branch A C C 1 D B master feat D feat2 E F E F
  26. Conflict during merge A C C 1 D B E

    master feat Let’s try fixing the conflict. First, we need to know what file(s) is/are having conflict(s). Do the command git status
  27. Conflict during merge A C C 1 D B E

    master feat We identified the conflicted file, now let’s check the content. Simply open the file. Using text editor or vim
  28. Conflict during merge A C C 1 D B E

    master feat Conflict happens when the same line of code/content was modified on both branches.
  29. Conflict during merge A C C 1 D B E

    master feat HEAD is pointing to the current content of the file which is marked from <<<<< to ===== Below ===== is/are the changes of the branch that you are trying to merge.
  30. Conflict during merge A C C 1 D B E

    master feat There are three ways to fix this...
  31. Conflict during merge A C C 1 D B E

    master feat Either you retain the content...
  32. Conflict during merge A C C 1 D B E

    master feat Or replace the content with the merged branch...
  33. Conflict during merge A C C 1 D B E

    master feat OR merge them both...
  34. Conflict during merge A C C 1 D B E

    master feat Once you have decided, save the file then simply stage the changes by doing git add <file>
  35. Conflict during merge A C C 1 D B E

    master feat Then conclude the merge by committing the change(s) git commit -m “Fixed merge conflict”
  36. Conflict during merge A C C 1 D B E

    master feat AND YOU’RE DONE!! (merge)
  37. Conflict during rebase A C C 1 D B master

    feat Even rebasing a branch can also have conflicts D
  38. Conflict during rebase A C C 1 D B master

    feat And it gives different kind of error unlike merge conflict D
  39. Conflict during rebase A C C 1 D B master

    feat First, we need to know the conflicts. Do the command git status D
  40. Conflict during rebase A C C 1 D B master

    feat Then resolve the conflict by editing the file just how we do it with merge conflict. Then stage the file using git add D
  41. Conflict during rebase A C C 1 D B master

    feat Once the change is staged. You can now traverse to the next commit. Do the command git rebase --continue D
  42. Conflict during rebase A C C 1 D B master

    feat If no other conflict arises, it automatically fast forward to the latest commit of the branch. D
  43. Tagging In git, tagging operates in a simple manner that

    approximates other VCSs. To mark a point in your code timeline with a tag: git tag <tag name>
  44. Tagging a timeline A C C 1 D B master

    feat D feat2 E F E F A We tag the commits from A-D for Alpha Release
  45. Remotes To be able to collaborate on any git project,

    you need to know how to manage your remote repositories. Remote repositories are versions of your project that are hosted on the Internet or network somewhere.
  46. Remotes A remote called origin is automatically created if you

    cloned a remote repository. The full address of that remote can be viewed with: git remote -v
  47. We mark each node with remote names, namely: origin, test,

    dev, live (staging) staging (live) production (test) test (origin) developer
  48. developer 1 cannot push and pull commits directly from other

    remotes except test (staging) staging (live) production (test) test (origin) developer push pull
  49. In a large scale project this is a good practice

    as it prevents the developer to mess up our live server. (Chuck Norris Approves) (staging) staging (live) production (test) test (origin) developer push pull
  50. Push Pushing with Git is the sending of local changes

    to a colleague or community repository with sufficiently open permissions as to allow you to write to it. git push <remote name>
  51. To retrieve remote changes without merging them into your local

    branches, simply fetch the blobs. It does not merge the changes until you told to do so. git fetch <remote name> git merge <remote/branch> Fetch
  52. Pull Pull is the combination of fetch and merge. No

    questions asked (except on conflicts). git pull <remote> <branch>
  53. Replicate this git history A C C 1 D B

    master feat1 D feat2 E F E F feat3 Branch G H H