Skip to content

Instantly share code, notes, and snippets.

@Furao
Last active September 27, 2015 17:18
Show Gist options
  • Save Furao/1304855 to your computer and use it in GitHub Desktop.
Save Furao/1304855 to your computer and use it in GitHub Desktop.
Useful git commands I always need to look up.
# Move a subdirectory from 1 repository to another
# Source Repo
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>
git mv <directory 1 contents> <directory 1>
git commit
# Destination Repo
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
# Delete local Tag
git tag -d 1.0
# Delete remote Tag
git push origin :refs/tags/1.0
# Merge unpushed logs when pulling
# This might be dangerous
git pull --rebase
# Push new local branch to origin
git push origin <branch_name>
# Remove untracked files
git clean -f
# Single patch file from current HEAD to master. Includes any commit messages.
git format-patch master --stdout > {name}.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment