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
  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
  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.
  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.
  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.
  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.
  7. BRANCHES checkout > git clone <clone-url> > git checkout -b

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

    <new-branch> -- do your changes –- > git commit –am “message” > git push origin <new-branch> 1 2 3 4 clone your changes branch push ORIGIN LOCAL origin / main origin / my-feature local / main local / my-feature
  9. origin / main origin / my-feature PULL REQUEST (PR) PULL

    REQUEST Let’s go to github >> AUTOMATIC MERGE origin / main origin / main
  10. 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.
  11. ORIGIN LOCAL origin / main local / main UPDATE LOCAL

    fetch / pull > git fetch > git branch (optional) > git status (optional) > git pull
  12. origin / main origin / my-feature PULL REQUEST (PR) PULL

    REQUEST AUTOMATIC MERGE origin / main origin / main
  13. 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
  14. 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.
  15. 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
  16. 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
  17. How do I properly force a Git push? git push

    origin <your_branch_name> --force
  18. 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
  19. 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