Git - Introduction

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Introduction to Git

Rolf Wuthrich
Concordia University
Introduction
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 was originally authored by Linus Torvalds in 2005 for development of the Linux kernel, with other
kernel developers contributing to its initial development. Since 2005, Junio Hamano has been the
core maintainer.
Overview

Remote
repository

Alice Local
repository
Bob
Local
repository
Git clone Remote
repository

git clone

Alice Local
repository

4
Git clone
JupyterLab GUI Terminal

git clone https://github.com/concordia-grad-computing-seminars/data-engineering.git


Creating your own branch

my-feature-branch

git checkout –b my-feature-branch

main branch
Making commits to your branch

commits added to your branch


Changes you want to track in your branch
can be recorded in your local repository by
my-feature-branch commits

Commits happen in two steps:


1. Adding the file with changes to the
staging area:
git add <file>
2. Committing all files inside the staging
main branch
area:
git commit –m “Commit message”
Lost ?

▪ When working with git it is very common to loose track of what exactly is
committed / changed /staged etc…
▪ Other operations too can add to the confusion (we will soon see more of
them)
▪ Your best friend to know what is the status of your local repository and
suggestions on what should be done is the command:

git status

8
Keeping your local repository in sync with
remote repository

9
Creating your own branch

my-feature-branch

git checkout –b my-feature-branch

main branch
Making commits to your branch
commits added to your branch

my-feature-branch

main branch
Commits added to main branch
commits added to your branch

my-feature-branch

main branch

commits added to main branch


Rebase your branch Imported commits from main branch

commits added to your branch Commits of your branch

my-feature-branch

git rebase origin/main

main branch

commits added to main branch


Resolving conflicts during rebase

14
Possible conflicts during rebase

▪ Delete conflicts
▪ A file you have modified was deleted on the main branch
▪ Merge conflicts
▪ A file has modifications from you and the main branch and these
modifications are conflicting

15
Resolving conflicts during rebase

▪ Read message(s) from git


▪ Use git status to guide you
▪ If you need to start over use:
git rebase --abort
▪ If too complex to resolve conflicts (e.g. when addressing conflicts with
jupyter notebooks) consider this approach:
▪ Copy your version of the file to another file/location
▪ Force accepting the version from origin/main:
git checkout --ours <file_to_get_from_main_branch>
▪ Compare the two file versions and solve conflicts

16

You might also like