https://github.com/huang-x-h/git-bonus
Git command colletion
https://github.com/huang-x-h/git-bonus
command git tricks
Last synced: about 2 months ago
JSON representation
Git command colletion
- Host: GitHub
- URL: https://github.com/huang-x-h/git-bonus
- Owner: huang-x-h
- License: mit
- Created: 2017-05-10T03:21:43.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-08-17T09:09:59.000Z (almost 7 years ago)
- Last Synced: 2025-01-23T05:20:02.556Z (over 1 year ago)
- Topics: command, git, tricks
- Language: JavaScript
- Size: 13.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Git bonus
> Collection of git commands
* [Clone a single branch in git](#clone-a-single-branch-in-git)
* [Compare two revisions of a file](#compare-two-revisions-of-a-file)
* [Compare current staged file against the repository](#compare-current-staged-file-against-the-repository)
* [Compare current unstaged file against the repository](#compare-current-unstaged-file-against-the-repository)
* [Delete a branch on a remote repository](#delete-a-branch-on-a-remote-repository)
* [Checkout a branch on a remote repository](#checkout-a-branch-on-a-remote-repository)
* [Undo the last commit, leaving changes in the the index](#undo-the-last-commit,-leaving-changes-in-the-the-index)
* [Discard all local changes in your working directory](#discard-all-local-changes-in-your-working-directory)
* [Undo git add before commit](#undo-git-add-before-commit)
* [Local branch look identical to remote branch](#local-branch-look-identical-to-remote-branch)
* [Caching you HTTPS password in git](#caching-you-https-password-in-git)
* [Commit case-sensitive only filename changes in git](#commit-case-sensitive-only-filename-changes-in-git)
* [Squash Multiple Commits](#squash-multiple-commits)
* [Stash Uncommitted Changes](#stash-uncommitted-changes)
* [Who changed what and when in ](#who-changed-what-and-when-in-)
* [Create branch without any parents](#create-branch-without-any-parents)
* [Delete local branches that have been removed from remote on fetch/pull](#delete-local-branches-that-have-been-removed-from-remote-on-fetch/pull)
* [Enable Git's autosquash feature by default](#enable-git's-autosquash-feature-by-default)
* [Quickly checkout the previous branch you were on](#quickly-checkout-the-previous-branch-you-were-on)
* [Delete local branches which have already been merged into master](#delete-local-branches-which-have-already-been-merged-into-master)
* [Want to change the commit message](#want-to-change-the-commit-message)
* [Add files to the previous commit](#add-files-to-the-previous-commit)
* [To push a single tag or all tags](#to-push-a-single-tag-or-all-tags)
* [Count number of lines in a git repository](#count-number-of-lines-in-a-git-repository)
* [Count number of lines changed between two commit](#count-number-of-lines-changed-between-two-commit)
* [How to remove a submodule](#how-to-remove-a-submodule)
## Clone a single branch in git
```sh
git clone user@git-server:project_name.git -b branch_name /some/folder
```
## Compare two revisions of a file
```sh
git diff
```
## Compare current staged file against the repository
```sh
git diff --staged
```
## Compare current unstaged file against the repository
```sh
git diff
```
## Delete a branch on a remote repository
```sh
git push origin :mybranchname
```
## Checkout a branch on a remote repository
```sh
git checkout -b mybranchname origin/mybranchname
```
## Undo the last commit, leaving changes in the the index
```sh
git reset --soft HEAD^
```
## Discard all local changes in your working directory
```sh
git reset --hard HEAD
```
## Undo git add before commit
```sh
git reset
```
## Local branch look identical to remote branch
```sh
git reset --hard origin/master
```
## Caching you HTTPS password in git
```sh
git config --global credential.helper store
```
## Commit case-sensitive only filename changes in git
```sh
git mv -f OldFileNameCase newfilenamecase
```
## Squash Multiple Commits
```sh
git rebase -i HEAD~2
```
## Stash Uncommitted Changes
```sh
git stash
```
## Who changed what and when in
```sh
git blame
```
## Create branch without any parents
```sh
git checkout --orphan mybranchname
```
## Delete local branches that have been removed from remote on fetch/pull
```sh
git config --global fetch.prune true
```
## Enable Git's autosquash feature by default
```sh
git config --global rebase.autosquash true
```
## Quickly checkout the previous branch you were on
```sh
git checkout -
```
## Delete local branches which have already been merged into master
```sh
git branch --merged master | grep -v "master" | xargs -n 1 git branch -d
```
## Want to change the commit message
```sh
git commit --amend -m "New commit message"
```
## Add files to the previous commit
```sh
git add file
git commit --amend --no-edit
```
## To push a single tag or all tags
```sh
git push origin
git push --tags
```
## Count number of lines in a git repository
```sh
git ls-files | xargs cat | wc -l
```
## Count number of lines changed between two commit
```sh
git diff --shortstat
```
## How to remove a submodule
```sh
1.Delete the relevant section from the .gitmodules file
rm -f .gitmodules
2.Stage the .gitmodules changes
git add .gitmodules
3.Delete the relevant section from .git/config
rm -f .git/config
4.Remove the submodule files from the working tree and index
git rm --cached path_to_submodule
5.Remove the submodule's .git directory
rm -rf .git/modules/path_to_submodule
6.Commit the changes
git commit -m "Removed submodule "
```
# Related
> git-tips https://github.com/git-tips/tips