# Git

Random stuff to do with Git


# So you fucked up the last commit and pushed it

# Delete the last commit and rewrite history

$ git reset --hard HEAD^
HEAD is now at goodhash Update

$ git push -f origin master
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/<username>/<repository>
 + badhash...goodhash master -> master (forced update)

# Using Github Tokens

# Create a token

You can create a new token here (opens new window)

  • Click on Generate new token

  • Give the token a name

  • Give permissions to repo by checking the box

  • Copy your token

# Pulling from a private repo

GITHUB_TOKEN=5c2ebb32a2438a1669e580c1fdb0fd84395daded

GITHUB_REPO=github.com/<username>/<Repo>.git

cd /my/clone/location
git clone https://$GITHUB_TOKEN@$GITHUB_REPO .

# Pushing to a private repo

GITHUB_TOKEN=5c2ebb32a2438a1669e580c1fdb0fd84395daded

GITHUB_REPO=github.com/<username>/<Repo>.git

cd /my/local/repo
git init
git add -A

## You may need to specify your identity first
git config --global user.email "my@email.address"
git config --global user.name "My Name"

git commit -m 'Commit Message'
git remote add origin https://$GITHUB_TOKEN@$GITHUB_REPO
git push -f origin master

DANGER

Using the -f flag will overwrite your existing commits. Use only if you are sure you want to do this.

# Use Windows CA Store

Switch the CA provider from openssl to schannel
This may be needed if you use a self-signed certificate.

git config --global http.sslBackend schannel

# Use pageant with VSCode

Add a new environment variable called GIT_SSH and point the variable to a copy of plink.exe If you've never connected before, manually connect to the server with putty to save the host key first.

Last Updated: 2022/07/30 18:10+00:00