Home

Git cheat sheet

Save git password locally so that it isn't asked every time

If you haven't cloned yet:

git clone https://<USERNAME>:<PASSWORD>@github.com/path/to/repo.git

If you have already cloned:

git remote set-url origin https://<USERNAME>:<PASSWORD>@github.com/path/to/repo.git

or

echo "https://<USERNAME>:<PASSWORD>@github.com/path/to/repo.git" > ~/.git-credentials

Ignore changes only locally without affecting the global .gitignore

Edit .git/info/exclude as if it were a normal .gitignore

Recover stashed changes

  1. Checkout the branch where you want those changes.
  2. git stash apply
  3. git diff
  4. git stash drop

Set your origin branch as the default branch where to push

git push --set-upstream origin your-branch-name

Delete the last n commits from local and remote (Github for example)

git reset --hard HEAD~n # to delete last 2 commits, n=2
git push origin --force