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.
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
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.
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.
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.
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.
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.
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
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.
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