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

GIT Basics for Software Projects

GIT Basics for Software Projects

Related to the session conducted at Faculty of Information Technology, University of Moratuwa on 2021/09/11, focusing on basic git workflows for their level 2 software projects.

Nishan Chathuranga

September 11, 2021
Tweet

More Decks by Nishan Chathuranga

Other Decks in Programming

Transcript

  1. GIT Basics
    for Software
    Projects
    NISHAN CHATHURANGA
    Software Engineer
    99X (Pvt) Ltd.
    University of Moratuwa
    Faculty of Information Technology

    View full-size slide

  2. Table of Contents
    What is version controlling
    and why we need Git.
    Merging branches
    01
    WHAT & WHY CLONING & FORKING BRANCHES
    MERGE & CONFLICTS OTHER USEFULL
    COMMANDS
    Q/A
    02 03
    04 05 06
    Getting started by cloning
    and forking
    Branching out from a base
    repository
    Rebasing, undo commits &
    Stashing
    Conclusion
    Session progress References

    View full-size slide

  3. Version
    Controlling
    Version control, also known as source control, is
    the practice of tracking and managing changes
    to software code. Version control systems are
    software tools that help software teams manage
    changes to source code over time.

    View full-size slide

  4. Git is a free and open source distributed version
    control system designed to handle everything from
    small to very large projects with speed and
    efficiency.
    Git is easy to learn and has a tiny footprint with
    lightning fast performance.
    GitHub, Inc. is a provider of Internet
    hosting for software development and
    version control using Git. It offers the
    distributed version control and source
    code management functionality of Git, plus
    its own features.

    View full-size slide

  5. Branch
    A version of the repository
    that diverges from the main
    working project
    A repository is a folder whose
    contents are tracked by git. It
    is
    also known as a repo, in
    simple terms.
    Clone
    Repository
    A clone is a copy of a
    repository or the action of
    copying a
    repository.

    View full-size slide

  6. Push
    Updates a remote branch
    with the commits made to
    the current branch. You are
    literally “pushing” your
    changes onto the remote.
    Adding/saving the changes to
    the local repository
    HEAD
    Commit
    HEAD is a reference
    variable used to denote the
    most current commit of the
    repository in
    which you are working.
    When you add a new
    commit, HEAD will then
    become that new
    commit.

    View full-size slide

  7. GETTING STARTED
    clone /add / commit / push

    View full-size slide

  8. BRANCHES
    checkout
    > git clone
    > git checkout -b
    -- do your changes –-
    > git commit –am “message”
    > git push origin
    1
    2
    3
    4
    clone
    your changes
    branch
    push
    ORIGIN
    LOCAL
    origin / main origin / my-feature
    local / main local / my-feature

    View full-size slide

  9. BRANCHES
    checkout
    > git clone
    > git checkout -b
    -- do your changes –-
    > git commit –am “message”
    > git push origin
    1
    2
    3
    4
    clone
    your changes
    branch
    push
    ORIGIN
    LOCAL
    origin / main origin / my-feature
    local / main local / my-feature

    View full-size slide

  10. origin / main origin / my-feature
    PULL REQUEST (PR)
    PULL REQUEST
    Let’s go to github >>
    AUTOMATIC MERGE
    origin / main
    origin / main

    View full-size slide

  11. ORIGIN
    LOCAL
    origin / main
    local / main
    DIVERGING
    ORIGIN & LOCAL
    Over time, remote repository (origin) will
    diverge from your local copy (clone), due
    to it getting updated from the pull requests
    by other team members. So we need to
    update local main branch frequently, and
    also you might need branches created by
    others as well, so we need to get those
    too.

    View full-size slide

  12. ORIGIN
    LOCAL
    origin / main
    local / main
    UPDATE LOCAL
    fetch / pull
    > git fetch
    > git branch (optional)
    > git status (optional)
    > git pull

    View full-size slide

  13. LET’S
    GO BACK

    View full-size slide

  14. origin / main origin / my-feature
    PULL REQUEST (PR)
    PULL REQUEST
    AUTOMATIC MERGE
    origin / main
    origin / main

    View full-size slide

  15. MERGE
    CONFLICTS
    merge or rebase
    1
    2
    3
    4
    pull
    resolve conflicts +
    commit
    merge
    push
    ORIGIN
    LOCAL
    origin / main origin / my-feature
    local / main local / my-feature
    > git checkout main
    > git pull
    > git checkout my-feature
    > git merge main
    -- OR –-
    > git checkout my-feature
    > git rebase main

    View full-size slide

  16. The git merge command lets us take independent branches
    of development and combine them into a single branch.
    MERGE
    MERGE VS REBASE
    REBASE
    Git rebase is yet another alternative to merging used to
    integrate another branch with the branch where you’re
    currently working, except it keeps a linear commit history.

    View full-size slide

  17. Few more
    useful things to
    know

    View full-size slide

  18. How do I undo
    the most recent
    local commits in
    Git?
    git reset --hard HEAD~1
    Change this to “3” if you
    want to go back 3
    commits

    View full-size slide

  19. Move the most
    recent
    commit(s) to a
    new branch
    with Git
    git checkout -b newbranch
    git branch -f master HEAD~3
    Change this to “1” if you
    only did one commit

    View full-size slide

  20. How do I
    properly force a
    Git push?
    git push origin --force

    View full-size slide

  21. CREDITS: This presentation template was created by
    Slidesgo, including icons by Flaticon, infographics &
    images by Freepik and illustrations by Stories
    Thank you!
    Does anyone have any questions?
    [email protected]
    @NishanTheDev
    linkedin.com/in/nishanchathuranga
    © 2021/Sept. GIT Basics by Nishan Wickramarathna is licensed under CC BY 2.0
    nishanc.medium.com
    youtube.com/NishanChathuranga

    View full-size slide

  22. GIT CLIENTS
    ● Gitkraken -
    https://www.gitkraken.com/pricing
    ● GitExtensions - http://gitextensions.github.io/
    ● Sourcetree -
    https://www.sourcetreeapp.com/
    ● Tower - https://www.git-tower.com/students/
    Resources
    VIDEO TUTORIALS
    ● Git It? How to use Git and Github -
    https://www.youtube.com/watch?v=HkdAHX
    oRtos
    ● 13 Advanced (but useful) Git Techniques and
    Shortcuts -
    https://www.youtube.com/watch?v=ecK3Eny
    GD8o
    ● Git Tutorial for Beginners: Learn Git in 1
    Hour -
    https://www.youtube.com/watch?v=8JJ101D3
    knE

    View full-size slide