wallace11
4/22/2018 - 9:56 AM

Git

DescriptionCommandReference
Store credentialsgit config credential.helper store
Allow no comment on commitgit config --global alias.nccommit 'commit -a --allow-empty-message -m ""'Source
Undo a commitgit reset HEAD~
List remotesgit remote -v
Change remotegit remote set-url origin <URL>Reference
Append to last commitgit 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

Migrating

git lfs migrate import --include="*.mp4" --include-ref=refs/heads/master
git push --force

Commands

git lfs ls-files

Cloning

git lfs install
git lfs pull