![gnugen logo](assets/gnugen_white_trans.svg) # just do *git* *Introduction*
## Slides Available at: [gnugen.ch/en/guides/](https://gnugen.ch/en/guides/)
## 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 (Terminal)](#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...

what does that mean for me?

  • Events (Just do Git)
  • Want to talk about free software?
    • We have Matrix / Telegram chats rooms
  • Need help installing Linux?
  • Need help with linux or other free software?

contact us! gnugen.ch/en/contact

# 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

  • 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

  • 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

  • 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 (Terminal)

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
  • Important: The Unix shell is not the same as PowerShell!

UNIX Shell (Terminal)

What is a command?

  • A command is just an application
  • Execute commands using the following format
  • 
    alain@gnugen:~ $ command argument1 argument2 ...
                                
  • here the command "command" is being executed with "argument1" and "argument2" as arguments

UNIX Shell (Terminal)

What is a command?

  • Flags are special arguments, that some cli application support, they are optional
  • 
    alain@gnugen:~ $ command --name alain argument1 ...
                                
  • here the command "command" is being executed with the argument "argument1" and the flag "name" using "alain" as an argument

UNIX Shell (Terminal)

The three most important commands

  • pwd
    (print working directory) — show in which directory you currently are
  • 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?


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

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

alain@gnugen:~ $ ls -a Documents/
. .. .a-secret.file EPFL 'random stuff' Notes.txt
                        

Useful commands

Step into and out of a directory


alain@gnugen:~ $ cd
                        

alain@gnugen:~ $ cd Documents
                        

alain@gnugen:Documents $ cd ../
                        

Useful commands

Create a new folder/directory


alain@gnugen:~ $ mkdir newfreesoftwareproject
                        

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

alain@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
## push your changes to GitHub/GitLab ```bash $ git push ```

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 log, 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 - GitLab tutorial is on [gnugen.ch/en/guides](https://gnugen.ch/en/guides/) - 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!

just do git



Survey: