Skip to content

Instantly share code, notes, and snippets.

@wallace11
Last active October 20, 2019 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wallace11/ae97675e3f82941854626f8a7ed32458 to your computer and use it in GitHub Desktop.
Save wallace11/ae97675e3f82941854626f8a7ed32458 to your computer and use it in GitHub Desktop.
Description Command Reference
Store credentials git config credential.helper store
Allow no comment on commit git config --global alias.nccommit 'commit -a --allow-empty-message -m ""' Source
Undo a commit git reset HEAD~
List remotes git remote -v
Change remote git remote set-url origin <URL> Reference
Append to last commit git commit --amend

Fresh start

  1. create a new repository that has the initial commit that you want

    mkdir foo; cd foo; git init; ...; git commit

  2. set up a remote

    git remote add origin <url-of-remote>
    git branch --set-upstream master origin/master
    
  3. push your new history

    `git push -f``

  4. delete obsolete remote branches

    git push origin :deprecated-branch

Source

Rebasing

Just rebase

git fetch origin
git reset --hard origin/master

Rebase fork

  1. Add the remote, call it "upstream":

    git remote add upstream https://github.com/whoever/whatever.git

  2. Fetch all the branches of that remote into remote-tracking branches, such as upstream/master:

    git fetch upstream

  3. Make sure that you're on your master branch:

    git checkout master

  4. Rewrite your master branch so that any commits of yours that aren't already in upstream/master are replayed on top of that other branch:

    git rebase upstream/master

Securely store credentials

Option 1: libsecret

  • Get libsecret and gnome-keyring (seahorse for GUI)
  • git config --global credential.helper libsecret

Option 2: netrc

source

  • Get gnupg
  • Script: https://raw.githubusercontent.com/git/git/master/contrib/credential/netrc/git-credential-netrc
    • Arch: /usr/share/git/credential/netrc/git-credential-netrc
    • Ubuntu: /usr/share/doc/git/contrib/credential/netrc/git-credential-netrc
  • Create a new file (preferably ~/.netrc):
    machine github.com
    protocol <http|https|ssh>
    login <username>
    password <password>
    
  • Generate a new key (if there's none already): gpg --gen-key
  • Encrypt the file: gpg -e -r <email> ~/.netrc
  • git config --global credential.helper "netrc -f ~/.netrc -v"
    • git-credentials- prefix will be automatically prepended to form git-credentials-netrc
    • Can add -d for debugging
    • For more info, git-credentials-netrc --help

More options:

https://github.com/git/git/tree/master/contrib/credential

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment