Git
Initialise new repository and push

Change to the project directory. Ensure .gitignore file has been created in directory and initialise git repository.

git init
git add .
git commit -m "Bootstrap project"

Create new repository in GitHub and push

git remote add origin https://github.com/ianhomer/my-project-name.git
git push -u origin master
Simple clone, add, commit and push

Clone

git clone [email protected]:ianhomer/ianhomer.git
git clone https://github.com/ianhomer/ianhomer.git

Status

git status

Add all, new and modified or modified and delete.

git add -A
git add .
git add -u

Commit changes

git commit

Push

git push

Pull

git pull
Prune branches

Remove non-existent remote branches from local

git remote prune origin   

List local branches ordered by date last modified => help deleting redundant branches

git branch --sort=committerdate --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
SSH Key switching

Change SSH key being used in

vi ~/.ssh/config

Delete keys previously loaded

ssh-add -D    

Test with

ssh -T [email protected] -v
ssh-add -l
Configure different keys for different repositories

Register alternative identify in the ~/.ssh/config file

Host github.com-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_personal
ssh-add ~/.ssh/id_rsa_personal
    

In the project directory

git remote set-url origin [email protected]:ianhomer/try-git
git config user.name "myname" 
git config user.email "[email protected]"
Credentials Helper

The credentials helper can help reduce password re-entry for HTTPS URLs. Note that For SSH URLs a SSH key is used to authenticate. Enable the credentials helper on OSX with - see Caching your GitHub password in Git for other systems.

git config --global credential.helper osxkeychain
Create a downstream only fork.

This pattern is useful for small prototypes and learning exercises based on base line project with no intention to push changes back upstream. Create "my-exercise" repository in GitHub web interface

git clone https://github.com/ianhomer/purplepip-project my-exercise
cd my-exercise
git remote set-url origin https://github.com/ianhomer/my-exercise
git push -u origin master

Add upstream repository and disable upstream pushes

git remote add upstream https://github.com/ianhomer/purplepip-project
git remote set-url --push upstream DISABLE
git remote -v

To sync the fork, you can fetch upstream changes and merge into local master

git fetch upstream
git checkout master
git merge upstream/master
Signing commits

Set up local

brew install gpg pinentry
gpg --gen-key
git config --global user.signingkey YOUR-KEY    
git config --global gpg.program gpg
git config --global commit.gpgsign true
export GPG_TTY=(tty)

Set GPG key in git service

gpg --list-keys
gpg --armor --export YOUR-KEY

And for GitHub, profile -> settings -> SSH and GPG keys -> new GPG key and copy in your PUBLIC KEY BLOCK.

Then commits going forward should be signed.

Thanks