Skip to content

Instantly share code, notes, and snippets.

@marianabocoi
Last active April 23, 2023 20:15
Show Gist options
  • Save marianabocoi/d05951ffcb80f6a9c4356d6978aa960f to your computer and use it in GitHub Desktop.
Save marianabocoi/d05951ffcb80f6a9c4356d6978aa960f to your computer and use it in GitHub Desktop.
Workshop from PinkProgramming Sunday event in Stockholm from April 2023

Git Workshop - Pink Programming April 2023

Setup git commandline

Windows

We will use Git Bash: https://gitforwindows.org

Linux/Unix

Official git documentation https://git-scm.com/download/linux

Mac

if ypu do not have brew, install with:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

then

brew install git

Configure your name and email

In a terminal run the following command to set your username:

git config --global user.name "FIRST_NAME LAST_NAME"

set your email address:

git config --global user.email "MY_NAME@example.com"

Git theory

GitHub account

If you do not have a GitHub account then please create one before: https://github.com

Difference between git and GitHub

Git handles versioning and GitHub is the cloud service that hosts your code online.
git-tutorial/git-vs-github

Github alternatives

There are several alternatives to GitHub. These are the most common:

Commandline basics

Learning to do everything on the command-line gives a lot of flexibility, so this workshop as much as possible will be done on the commandline.

Changing directories

Go to users home directory that usually contains Documents or Desktop folders.

cd 

Change directory to a specific folder

cd folder_name

Special folders in the commandline

  • . current folder
  • .. one folder back/higher/up
  • / the base of the operating system
  • - previous folder
  • ~ users home folder

List current directory

pwd

List all current files/direcories in folder including hidden files

ls -la

When stuck type this

ctrl+c - will close any active program

Create an empty file

touch filename.txt

Create a folder

mkdir folder-name

Remove folder

You might get asked if you really wanted to remove certain files. If you do not want the safety you can also use -f

rm -r folder

Basics of vi / vim

Most terminals have vi available. It is a benefit to know how to navigate it and recognise when you land in the editor. Vi is an older version of Vim (Vi improved). To start editing a file type:

vi filename.txt

Then press i to go into --INSERT-- mode so you can type the text. (--INSERT-- will show at the bottom)

When you are done

If you get stuck you can always close the terminal window and start again.

Vim vs Nano

Another editor that might show by default is Nano. This has a different interface compared to Vim.

Git in practice

For a more complete and structured tutorial check Git tutorial

Create a local repository

On the commandline navigate to the folder .

git init

See the status of the repository

git status

Check the history of the repository

git log

Check the difference from the last commit

git diff

Add changes to the stage area before a commit

git add folder_or_filename

Commit the changes

git commit -m "Description of what the changes were"

Conventional commit messages are often used in development teams as a guideline. Read more here: https://www.conventionalcommits.org/en/v1.0.0/

Collaboration & GitHub

Create ssh config for pushing code to GitHub and cloning

Generate key Configure it for your GitHub account

Create a repository on GitHub

Follow https://www.w3schools.com/git/git_remote_getstarted.asp

Merge conflicts

To simulate 2 people working on a repository you can create two different folders and clone the repository in each. then you can work in the two folders independently.

The commands I used:

git rebase origin/main
# there was a conflict in myawesomefile.txt
git add myawesomefile.txt
git rebase --continue
# got a vim window at the end to confirm the commit messages so I typed :wq

After these commands the git status shows you are 1 commit on top of main and the git log command now has the extra commit. Try it out!

More Git tutorials:

https://git-scm.com/doc/ext

More GitHub tutorials

https://skills.github.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment