Last active
February 17, 2022 11:58
-
-
Save gonatan/cfa279da2d33cfe84f962cdf6a1121b8 to your computer and use it in GitHub Desktop.
Git commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # fetch data from remote | |
| git fetch # fetch | |
| git fetch --all --prune # fetch deleted branches | |
| # undoing stuff | |
| git reset <file> # undo 'git add' before commit | |
| git reset --soft HEAD~1 # undo last 'git commit' and keep changes | |
| git reset --hard HEAD~1 # undo last 'git commit' and loose changes | |
| git reset --merge ORIG_HEAD # undo 'git merge' before push | |
| git checkout HEAD <file> # revert after a merge conflict corruption | |
| # working with branches | |
| git branch # list local branches | |
| git branch -a # list all branches | |
| git branch -d <branch> # delete local branch | |
| git branch -D <branch> # delete local branch although it is dirty | |
| git checkout -b <branch> # create new local branch from current local branch | |
| git push -u origin <branch> # push local branch to remote new branch | |
| git push origin --delete <branch> # delete remote branch | |
| # working with tags | |
| git tag <new_tag> # create tag | |
| git tag -d <old_tag> # delete tag | |
| git push origin --tags # publish tags | |
| git push origin :refs/tags/<old_tag> # publish deleted tag | |
| # working with submodules | |
| git submodule init && git submodule update # initialize submodules: usual version | |
| git submodule update --init # initialize submodules: short version | |
| git clone --recursive <parent-repository-url> # initialize submodules: clever version | |
| git submodule status # show status of submodules | |
| # working with upstreams | |
| git remote -v # list upstreams | |
| git remote set-url origin git@bitbucket.org:fourforbusiness/project.git # update upstream | |
| git config submodule.moduleName.url ssh://user@server/path # update upstream of submodule | |
| git submodule update --recursive --remote | |
| # other stuff | |
| git diff > mypatch.patch # create patch from changes in current working directory | |
| git stash show -p stash@{0} # diff against a stash | |
| git gc --prune=now --aggressive # reduce git repository size | |
| git log --all --decorate --oneline --graph # Show dense log | |
| # move submodule to main repo | |
| git rm --cached <submodule_path> | |
| git rm .gitmodules | |
| rm -rf <submodule_path>/.git | |
| git add <submodule_path> | |
| git commit -m "moved <name> submodule to main repository" | |
| # Git client debug | |
| # https://confluence.atlassian.com/bitbucketserverkb/git-clone-fails-due-when-cloning-via-ssh-879243661.html | |
| GIT_SSH_COMMAND="ssh -vvv" git fetch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment