Git

Contents

Handy Tricks for Git

This is primarily to avoid accidential upload of keys/config/etc to a git host, ie github.

git config --global core.excludesfile

vim <path/to/file>/.gitignore_global

Then populate it with the below plus anything that you might want:

# Config Files
conf.yml
conf.yaml
conf.eyaml

config.yml
config.yaml
config.eyaml

# Keys
key.txt
keys.txt

# Environments Files
.env

View current changes

git status

Undo changes on a particular file, aka rollback to previous commit.

git checkout -- <path/to/file.ext>

Blow away all current changes

git reset --hard

See local branchs

git branch

List all branchs

git branch -a

Switch branch

git checkout <branchname>

Create a new branch, switch to it & push it to remote

git checkout -b <branchname>
git push -u origin <branchname>

In the instance a commit is must be deleted, as opposed to reverting, etc.

git reset --hard HEAD^

# To remove last N commits
git reset --hard HEAD~2

# Push changes to remote. This will overwrite remote!!
git push origin -f

For instances with multiple SSH configs available.

  1. Get github SSH config name
cat ~/.ssh/config
  1. Add remote URL with the desired config name:
git remote set-url origin git@<user config name>:<User/Org name>/<repo name>.git

# Eg:
git remote set-url origin git@github.com:diabolical-ninja/yeltahir.com.git
  1. Add ssh passphrase to keychain
ssh-add -K ~/.ssh/id_rsa