![gnugen logo](assets/gnugen_white_trans.svg) # just do *git* *Introduction*
## Please help us improve! There will be a short survey at the end of the presentation
## Table of contents * [About gnugen](#about-gnugen) * [Git Overview](#overview) * [How (g)it works](#how-git-works) * [UNIX Shell](#shell) * [Basic workflow](#basic-workflow) * [Command Summary and Reference](#commands) * [Some practice](#some-practice)
# About gnugen

Who are we?

Promote free/libre software on the EPFL campus

free/libre software

Four fundamental freedoms

  • freedom to use: freely run parts of a program or not
  • freedom to study the source code
  • freedom to share the program
  • freedom to improve the program

free/libre software

But why?

  • Respect for the user
  • Accessible, inclusive
  • Privacy
  • Many more...
# Git Overview
## What is git? ![git logo](assets/git-logo.png)

What is git?

Git is a distributed version control system.

  • distributed
  • version control
## Why use git?

What is GitHub / GitLab?

provide functionality around git mostly for collaboration

  • git repository
  • issues
  • pull requests

What is GitHub / GitLab?

Stay tuned to get some practice!

# How (g)it works
## Commit

Commit

  • are like snapshots
  • contain changes since commit before
  • go back in time: you can see how your project looked like at every commit
![git commit illustration](assets/commit.svg)
## Branches

Branches

  • are like pointers to only one commit at a time
  • switch between branches to work on different things without interferance
  • especially useful when some incomplete changes make a project broken/not build/etc
  • also especially useful when collaborating
![git commit illustration](assets/branches.svg)
## Merge

Merge

  • combines two branches
  • by integrating the features of one branch into the other branch
  • can be done in the form of a merge/pull request on GitHub/GitLab
![git commit illustration](assets/merges.svg)
# UNIX Shell

UNIX Shell

Used to interact with git

  • Git is a command line (cli) tool
  • integrations into IDEs and different GUIs for Git exist
  • but the cli is the common ground since it's the same everywhere

UNIX Shell

The two most important commands

  • ls
    (list) — show contents of the directory we are currently in
  • cd
    (change directory) — change into an other folder

Useful commands

Which files are in this directory?


jonas@gnugen:~ $ ls
Documents Downloads Music Pictures Videos
						

jonas@gnugen:~ $ ls Documents/
EPFL 'random stuff' Notes.txt
						

Useful commands

Step into and out of a directory


jonas@gnugen:~ $ cd
						

jonas@gnugen:~ $ cd Documents
						

jonas@gnugen:Documents $ cd ../
						

Useful commands

Create a new folder/directory


jonas@gnugen:~ $ mkdir newfreesoftwareproject
						

jonas@gnugen:~ $ ls
Documents Downloads Music newfreesoftwareproject Pictures Videos
						

jonas@gnugen:~ $ cd newfreesoftwareproject
						

Useful commands

Other commands

  • move, copy, delete
  • text editors
  • system configuration
  • version control and collaboration -> git
  • ...
# basic workflow
## Start working on a new project New local project: ```bash $ cd your/project/directory $ git init ``` Existing repository on GitLab/GitHub: ``` $ cd directory/to/put/the/project/in $ git clone <your projects repository url> ```
## prepare changes of a file for the next commit `git add` selects which files and changes you add to your next commit: ```bash $ git add myfile.txt ``` check what is "staged" for the next commit: ```bash $ git status On branch main Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: myfile.txt ```
## create a commit (i.e. snapshot) ```bash $ git commit -m "added some lines to myfile.txt" ``` the commit message (`-m`): a place to write what you've changed

Representation of these steps

But why is the image cut?

# collaborative workflow

This is why!

by https://github.com/pushpankq/Git-Commands-
# collaborative workflow ## coming soon... come to our upcoming events about git to learn more about git, how to use it to collaborate efficiently and handle common mistakes [gnugen.ch](https://gnugen.ch)
# Command Summary and Reference

Summary of basic commands

  • git add, git commit: create a commit
  • git status, git diff, git show: show status and changes

Handling branches

  • checkout
  • merge

Using git with other people

  • pull
  • push

Handling small mistakes

  • commit --amend
  • reset HEAD^
# Some practice

Your choice!

  • a game to practice
  • setup of git and gitlab/github on your computer
## Some practice with ## Oh My Git! - open [ohmygit.org](https://ohmygit.org/) - click on the button labelled "Download the game!" below "Play the game!" - and follow the instructions for your OS
## Setup of git and gitlab/github - linux with your favorite package manager - macos with [brew](https://brew.sh/) or Xcode - windows with [git bash](https://gitforwindows.org/)

But first

Thank you!

![gnugen logo](assets/gnugen_white_trans.svg) ## just do *git* * Slides: https://gitlab.gnugen.ch/gnugen/presentations/just-do-git