Skip to content
Aleksey Midenkov edited this page Oct 7, 2018 · 1 revision
Keep HTTPS passwords longer:
git config --global credential.helper cache
git config --global credential.helper "cache --timeout=3600"
When HTTPS asks for password replace it with SSH:

git remote set-url origin [email protected]:<username>/<repo>.git (from here):

Create branch tracking remote:

git checkout -b local_branch remotes/origin/remote_branch

Attach local repo to remote (from here):
git remote add origin <remote_repo_url>
git push --all origin

If you want to set all of your branches to automatically use this remote repo when you use git pull, add --set-upstream to the push:

git push --all --set-upstream origin
Auto push after commit:

Create file in .git/hooks/post-commit that contains the following:

#!/bin/sh
git push
Undo a commit and redo
$ git commit ...              (1)
$ git reset --soft 'HEAD^'    (2)
$ edit                        (3)
$ git add ....                (4)
$ git commit -c ORIG_HEAD     (5)

This is what you want to undo

This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset". (The quotes may or may not be required in your shell)

Make corrections to working tree files.

Stage changes for commit.

"reset" copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.

Moving Files from one Git Repository to Another, Preserving History

Get files ready for the move:
git clone <git repository A url>
cd <git repository A directory>
git remote rm origin
git filter-branch --subdirectory-filter <directory 1> -- --all
mkdir <directory 1>
mv * <directory 1>
git add .
git commit
Merge files into new repository:
git clone <git repository B url>
cd <git repository B directory>
git remote add repo-A-branch <git repository A directory>
git pull repo-A-branch master
git remote rm repo-A-branch

Links

About merge strategies