Git Cheat Sheet

Initialise a folder locally to be source control repo

1git init

Add changed files to be staged ready for a commit ("." represents all files down from the current )

1git add . 

Commit changes

1git commit -m "this is a commit message"

Create a repo in github

Diagrams to follow.

attach a local repo to an empty repo in github

Diagrams to follow these commands usually pop out of github -

1git remote add origin git@github.com:r3adm3/mytestrepo.git
2git branch -M main
3git push -u origin main

clone a repo in github

TBD picture to go here

1#only needed if a generic source folder doesn't exist
2mkdir Source
3cd Source
4mkdir github
5cd github
6
7#the actual command needed
8git clone git@github.com:r3adm3/mytestrepo.git

check what remote repo a local git repo is attached to.

1git remote -v

push changes to github

1git push

Create a branch

1git branch mytestbranch

Create and switch to branch

1git checkout -b mytestbranch2

Switch to branch

1git checkout mytestbranch

list branches

1git branch

Pull requests and merges

TBD, diagrams to be added.

.gitconfig handy alias

1#stored in /home/username or c:\users\username
2
3[user]
4  name = FirstName LastName
5  email = emailaddress@emailprovider.com
6
7[alias]
8  lg = log --graph --pretty=format:'%C(green)%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(cyan)<%an>%Creset' --abbrev-commit --date=relative

use the alias to show you a list of all code commits and branches lifecycle

1git lg