git remote add -f RemoteName RemoteUrlgit subtree add --prefix Path/To/Put/Code NameOfRemote master --squashgit fetch NameOfRemote master
git subtree pull --prefix Path/To/Put/Code NameOfRemote master --squashVery useful when you are updating a project that you are rewriting. For example, say you are using semantic versioning and are wanting to start a new major version.
git checkout --orphan BRANCHGreat for cleaning up local branches that aren't being used any more.
git checkout master
git branch --merged | grep -v "\*" | xargs -n 1 git branch -dgit update-index --assume-unchanged [directory|file]git update-index --no-assume-unchanged [directory|file]Edit your .git/config and add ignore = dirty.
[submodule "path/to/submodule"]
path = path/to/submodule
url = git://github.com/username/repo.git
ignore = dirty
git clone -o upstream https://repo.gitAdd the file .git/info/exclude and fill it with the contents you want to ignore. This will ONLY apply to the
repository and will not be tracked by git.
git logCount the number of commits that you have made, let's say the previous 5 are your commits.
git rebase -i HEAD~5The first commit leave as pick the rest will need to be changed to squash. After that you will be able to
leave a new commit message or just leave as is to keep the commit messages from all previous commits.
git log -S[search term]Example:
git log -SThatOneFile.phpCopy a file from branch and put into staging.
git checkout BRANCH path/to/file.ext
# Real Life Examples
git checkout origin/featureBranch web/js/random.js
# Pulls into your current branch web/js/random.js from
# origin/featureBranch# Basic grep (case sensitive)
$ git grep 'search term'
# Case Insensitive search
$ git grep -i 'search term'
# Search within a directory
$ git grep 'search term' src/
# Search only files with `php` extension
$ git grep 'search term' -- '*.php'
# Grep in the 'src/` directory, only yml files
$ git grep 'search term' -- 'src/**.yml'
# Open files in vim
vim $(git grep --name-only 'search term' src/)git push origin localBranchName:remoteBranchNameUse Case: I will often use rebase, I will cut a branch off the branch I want to rebase and
do the rebase on the newly created branch. Once I am done, I will check the diff and see if
I screwed up. If it's all good, git push -f NOTICE: DO NOT git push -f unless you know
what you are doing.