Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

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.

Slide 5

Slide 5 text

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.

Slide 6

Slide 6 text

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.

Slide 7

Slide 7 text

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.

Slide 8

Slide 8 text

HANDS ON

Slide 9

Slide 9 text

GETTING STARTED clone /add / commit / push

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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.

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

LET’S GO BACK

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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.

Slide 21

Slide 21 text

FORKING

Slide 22

Slide 22 text

Few more useful things to know

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

No content