git checkout -b [new_branch_name]
git push [remote_name] [new_branch_name]
git remote show [remote_name]
git fetch [remote_name] [remote_branch_name]:[local_branch_name]
git checkout [local_branch_name]
Merge branch [B]
into branch [A]
git checkout [A]
git merge [B]
git checkout [A]
git checkout [B] [files_to_merge]
git add [files_to_merge]
git commit -m [commit_message]
git clone --branch [remote_branch_name] [URL]
Local:
git branch -d [local_branch_name]
On Remote:
git push origin --delete [remote_branch_name]
Show files that differ in current branch from branch [branch_name_a]
:
git diff --names-only [branch_name_a]
With diff
(compares all files, add the file name after the command to only compare a single file):
git diff [branch_name_a]..[branch_name_b]
With difftool
(compares all files, add the file name after the command to only compare a single file):
git difftool [branch_name_a]..[branch_name_b]
git fetch
git diff [local_branch_name] [remote_name]/[remote_branch_name]
git fetch
git merge
When you want to switch to a different branch and don't want to commit your changes you can stash them.
git stash
git stash list
git stash apply
git stash apply stash@{[number]}
git tag
git tag [tag_name]
git tag -a [tag_name] -m "[message]"
git tag -a [tag_name] [commit_hash]
git tag --delete [tag_name]
git push --delete [remote_name] [tag_name]
By default git push
does not push tags onto a remote. This is done by:
git push [remote_name] [branch_name] --tags
git checkout [tag_name]
git checkout [tag_name]
git checkout -b [new_branch_name]
or
git checkout -b [new_branch_name] [tag_name]
git clone --branch [tag_name] [URL]
git submodule add [URL_of_submodule] [directory_of_submodule]
git clone [URL]
git submodule init
git submodule update
or
git clone [URL] --recursive
git submodule add [URL_of_submodule] [directory_of_submodule]
cd [directory_of_submodule]
git checkout -b [submodule_branch] [submodule_remote]/[remote_submodule_branch]
cd -
git commit -am "[message]"
git push [remote] [branch]
Clone it:
git clone [URL] --recursive
or:
git clone [URL]
git submodule update --init -recursive
git submodule add [URL_of_submodule] [directory_of_submodule]
cd [directory_of_submodule]
git checkout [tag_name]
cd -
git commit -am "[message]"
git push [remote] [branch]
Clone it:
git clone [URL] --recursive
or:
git clone [URL]
git submodule update --init -recursive
- Delete the relevant section from
.gitmodules
- Delete the relevant section from
.git/config
- Delete the submodule from the repository
git rm --cached [directory_of_submodule]
- Delete the submodule from the config
rm -rf .git/modules/[directory_of_submodule]
- Commit the changes
git commit -m "Removed submodule [submodule_name]"
- Delete the submodule from the local drive
rm -rf [directory_of_submodule]
git rm [file]
git rm --cached [file]
git config --list
git config --list --show-origin
git config --global user.name [user_name]
git config --global user.email [email]
git config --global diff.tool vimdiff
git config --global difftool.prompt false
Open vim as diff tool:
git difftool
git config merge.tool vimdiff
git config merge.conflictstyle diff3
git config mergetool.prompt false
git config --global --unset [config_name]
git ls-tree -r master --name-only