Git
Contents
Git#
Git Command Reference#
Configuration#
Global git settings - stored in
~/.gitconfig
:$ git config --global user.name "My Name" $ git config --global user.emal "my@email.xyz"
Per repository settings - stored in
.git/config
:$ git config user.name "My Name" $ git config user.email "my@email.xyz"
Branches#
Switch to an existing branch:
$ git checkout <branch-name>
Create a new branch and check it out:
$ git checkout -b <branch-name>
Remotes#
List all remotes:
$ git remote -v
Rename a remote:
$ git remote rename <old-name> <new-name>
Revert Changes#
Create new changes that roll back the changes from a specific older commit:
$ git revert <commit-hash>
Git How-Tos#
How to Split Out a Folder Into a Separate Repository#
… and keep the git history!
Very heavily based on https://ao.ms/how-to-split-a-subdirectory-to-a-new-git-repository-and-keep-the-history/
Make a duplicate clone of the old repository. This copy of the repository will eventually become the new repository that holds only the selected folder that is split out. If there is a copy of the old repository sitting in the same directory, direct the duplicate clone to a folder with a different name (<new-repository>):
$ git clone <old-repository> <new-repository> $ cd <new-repository>
Check out the appropriate branch:
$ git checkout <branch>
Filter to keep only the contents of the desired folder:
$ fit filter-branch --prune-empty --subdirectory-filter <subdirectory>
Create a new git repository at your hoser of choice. This will be the new repository holding only the desired folder.
Configure the new repository as the remote:
$ git remote set-url origin <url-to-new-repository>
Push the contents of the new repository:
$ git push -u origin <branch>
Optionally, delete the folder from the old repository