Table of Contents

GIT

Overview

What is it?

How does it work?

GIT Commands

Get a repository

Create a new one

cd <REPO>
git init
ls -alh

Clone an existing one

git clone https://github.com/<USER>/<REPO>
cd <REPO>
ls -alh

Check the state it’s in

git status
git diff
git diff --cached
git log

Note: this may use the pager (less/more)

Get changes from others

Get changes from a specific remote, optionally integrating them into the current branch

git fetch <REMOTE> 
git pull <REMOTE>

You can always fetch the changes but pulling requires the local and remote branches to be somewhat aligned.

Push changes

git push <REMOTE> <BRANCH>
Github/Gitlab Regular Git
Changes are pushed to your account changes are pushed to a throw-away branch
Merged by using a PR/MR on the websiteMerged manually if no conflicts arise
Inspection by collaborators during MR No inspection until deployed
Do NOT push directly to master!

Mistakes and Corrections

From safe to loosing all local changes since last commit:

git stash
git reset
git reset --hard
git checkout <CLEAN> && git checkout -B <BRANCH>

Read the manual before loosing more of your changes than you wanted to reset!

Workflow

Workflow 1

Highly dependent on project/organization! But:

Workflow 2

Combined like this is a good way to start working:

git checkout master
git pull origin
git checkout -b addGitTalk
git diff
git status
git add [PATH]
git diff --cached
git commit
git push

</blockquote></HTML>

Work on a feature

  1. Create a new branch, which starts out identical to the current
  2. Work on the project
  3. Mark your changes as ready
  4. Check if all the changes look good and are marked for inclusion in the next commit
  5. Add your changes to the branch inside the repository
git checkout -b <NAME>
...
git add [PATH]
git diff; git diff --cached
git commit