Q: What is git?

a: version control system

Q: WHAT is A version control system

Creating Programming projects

file

// main.cpp
#include <iostream>

int main()
{
    int n;
    std::cin >> n;

    for (int i = 0; i < n; ++i)
    {
        std::cout << "printing: " << i;
        std::cout << '\n';    
    }
}

Project

// main.cpp
#include "input.h"
#include "printer.h"

int main()
{
    int n = get_input();

    Printer printer{"printing: "};
    for (int i = 0; i < n; ++i)
    {
        printer.print(i);
    }
}
// input.h
#ifndef INPUT_H
#define INPUT_H

[[nodiscard]] int get_input() noexcept;

#endif
// input.cpp
#include <iostream>

int get_input() noexcept
{
    int input;
    std::cin >> input;
    return input;
}
// printer.h
#ifndef PRINTER_H
#define PRINTER_H

#include <iostream>
#include <string>

class Printer
{
private:
    std::string msg;
public:
    Printer(std::string_view sv) : 
        msg{sv}
    {
    }
    
    template <typename T>
    void print(T&& x)
    {
         std::cout << msg << x << '\n';
    }
};

#endif

Project

main source code

resource files

test suite

CI/CD jobs

...

Project

Project

Project

TIME

Alpha
Beta
RC1
1.0
Patch 1
1.1

Project

TIME

Alpha
Beta
RC1
1.0
Patch 1
1.1

Project

TIME

Alpha
Beta
RC1
1.0
Patch 1
1.1
Alpha
Beta

Project

TIME

Alpha
Beta
RC1
1.0
Patch 1
1.1
Prototype
Enemy AI
Multiplayer
Better GFX
Optimizati
UI Poli
Ach

Q: VCS?

A:

TIME

VCS

Ctrl-Z++

Backup++

Cloud++

≈

VCS

Git

Subversion (SVN)

Mercurial (Hg)

:

...

Git

Github

vs

Git 101

repository (repo)
main branch
commit
HEAD

repository

unstaged changes
staging area
committed changes

repository

unstaged changes
staging area
committed changes
#include <iostream>
using namespace std;

int main()
{
    std::cout << "hllo wrld!r\n";
}
#include <iostream>
using namespace std;

int main()
{
    std::cout << "hello world!\n";
}

repository

unstaged changes
staging area
committed changes
#include <iostream>
using namespace std;

int main()
{
    std::cout << "hllo wrld!r\n";
}
main.cpp

repository

unstaged changes
staging area
committed changes
#include <iostream>
using namespace std;

int main()
{
    std::cout << "hllo wrld!r\n";
}
#include <iostream>
using namespace std;

int main()
{
    std::cout << "hello world!\n";
}
main.cpp

repository

unstaged changes
staging area
committed changes
#include <iostream>
using namespace std;

int main()
{
    std::cout << "hllo wrld!r\n";
}
#include <iostream>
using namespace std;

int main()
{
    std::cout << "hello world!\n";
}
main.cpp

repository

unstaged changes
staging area
committed changes
main.cpp
#include <iostream>
using namespace std;

int main()
{
    std::cout << "hllo wrld!r\n";
}
#include <iostream>
using namespace std;

int main()
{
    std::cout << "hello world!\n";
}

repository

unstaged changes
staging area
committed changes
main.cpp
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
input.h
video.cpp
ui.cpp
input.h
video.cpp
ui.cpp
renderer.h

repository

unstaged changes
staging area
committed changes
main.cpp
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
input.h
input.h
video.cpp
ui.cpp
renderer.h
video.cpp
ui.cpp

repository

unstaged changes
staging area
committed changes
main.cpp
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
input.h
input.h
video.cpp
ui.cpp
renderer.h
    main.cpp
    input.h
[M] video.cpp
[M] ui.cpp
    renderer.h

repository

unstaged changes
staging area
committed changes
main.cpp
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
input.h
video.cpp
ui.cpp
renderer.h
    main.cpp
    input.h
[M] video.cpp
[M] ui.cpp
    renderer.h
input.h

repository

unstaged changes
staging area
committed changes
main.cpp
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
input.h
video.cpp
ui.cpp
renderer.h
    main.cpp
    input.h
[M] video.cpp
[M] ui.cpp
    renderer.h
    main.cpp
[M] input.h
    video.cpp
    ui.cpp
    renderer.h

Git 101

repository (repo)
main branch
commit
HEAD
UC
SA
CC

using git

git

command line interface

git

command line interface

git init

git add

git commit

git status
git init
git init
unstaged changes
staging area
committed changes
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
git add [file]
unstaged changes
staging area
committed changes
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
git add main.cpp
unstaged changes
staging area
committed changes
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
git add *.cpp
unstaged changes
staging area
committed changes
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
git add .
unstaged changes
staging area
committed changes
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
git commit
unstaged changes
staging area
committed changes
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
git commit -m "Initial commit"
unstaged changes
staging area
committed changes
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
Initial commit
git status
unstaged changes
staging area
committed changes
main.cpp
input.h
video.cpp
ui.cpp
renderer.h
Initial commit

DEMO TIME #1

git init
git add
git commit
git status

BRANCHING

main branch

BRANCHING

main branch
dev branch

BRANCHING

main branch
dev branch

BRANCHING

main branch
dev branch
git branch dev
git checkout dev
git commit
git checkout main
git merge dev

BRANCHING

BRANCHING

HEAD
main

BRANCHING

HEAD
main
git branch dev
dev

BRANCHING

HEAD
main
...
git commit
dev

BRANCHING

HEAD
main
...
git commit
dev

BRANCHING

HEAD
main
git checkout dev
dev

BRANCHING

HEAD
main
dev
...
git commit

BRANCHING

HEAD
main
dev
...
git commit

BRANCHING

HEAD
main
dev
git branch feature
feature

BRANCHING

HEAD
main
dev
git checkout feature
feature

BRANCHING

HEAD
main
dev
feature
...
git commit

BRANCHING

HEAD
main
dev
feature
...
git commit

BRANCHING

HEAD
main
dev
feature
...
git commit

BRANCHING

HEAD
main
dev
feature
git checkout dev

BRANCHING

HEAD
main
dev
feature
git merge feature

BRANCHING

HEAD
main
dev
feature
...
git commit

BRANCHING

HEAD
main
dev
feature
git checkout main

BRANCHING

HEAD
main
dev
feature
git merge dev

merge conflicts

void greet()
{
    std::cout << "hello";
}
void greet()
{
    std::cout << "hi";
}
void greet()
{
    std::cout << "mornin\'";
}

DEMO TIME #2

git init
git add
git commit
git status
git branch
git checkout
git merge

remotes

remotes

Local

Remote

Local

Remote

Local

Remote

git push

Local

Remote

Local

Remote

git pull

GIT

By Jan Bielak