navi/cheats/git.cheat

98 lines
2.3 KiB
Text
Raw Normal View History

2019-09-20 10:38:58 -03:00
% git
2019-09-21 12:17:47 -05:00
# Set global git user name
2019-09-21 19:21:46 -03:00
git config --global user.name <name>
2019-09-20 10:38:58 -03:00
2019-09-21 12:17:47 -05:00
# Set global git user email
2019-09-21 19:21:46 -03:00
git config --global user.email <email>
2019-09-21 12:17:47 -05:00
# Initializes a git repository
git init
2019-09-27 09:45:32 +05:30
# Clone a git repository
git clone -b <branch_name> <repository> <clone_directory>
# View all available remote for a git repository
git remote --verbose
2019-09-21 12:17:47 -05:00
# Adds a remote for a git repository
2019-09-21 19:21:46 -03:00
git remote add <remote_name> <remote_url>
2019-09-20 10:38:58 -03:00
2019-09-27 09:45:32 +05:30
# Renames a remote for a git repository
git remote rename <old_remote_name> <new_remote_name>
# Remove a remote for a git repository
git remote remove <remote_name>
2019-09-20 10:38:58 -03:00
# Checkout to branch
git checkout <branch>
2019-09-21 12:17:47 -05:00
# Displays the current status of a git repository
git status
# Displays the changes made to a file
git diff <filename>
# Stages a changed file for commit
git add <filename>
# Stages all changed files for commit
git add .
# Saves the changes to a file in a commit
2019-09-22 12:10:51 -03:00
git commit -m <message>
2019-09-21 12:17:47 -05:00
# Pushes committed changes to remote repository
2019-09-21 19:21:46 -03:00
git push -u <remote_name> <branch_name>
2019-09-21 12:17:47 -05:00
# Pushes changes to a remote repository overwriting another branch
2019-09-21 19:21:46 -03:00
git push <remote_name> <branch>:<branch_to_overwrite>
2019-09-21 12:17:47 -05:00
# Overwrites remote branch with local branch changes
2019-09-21 19:21:46 -03:00
git push <remote_name> <branch_name> -f
2019-09-21 12:17:47 -05:00
# Pulls changes to a remote repo to the local repo
git pull --ff-only
# Merges changes on one branch into current branch
2019-09-21 19:21:46 -03:00
git merge <branch_name>
2019-09-21 12:17:47 -05:00
2019-09-27 09:45:32 +05:30
# Abort the current conflict resolution process, and try to reconstruct the pre-merge state.
git merge --abort
2019-09-21 12:17:47 -05:00
# Displays log of commits for a repo
git log
# Displays formatted log of commits for a repo
git log --all --decorate --oneline --graph
# Clear everything
git clean -dxf
# Sign all commits in a branch based on master
git rebase master -S -f
2019-09-21 19:21:46 -03:00
# See all open pull requests of a user on Github
2019-10-11 14:33:16 -03:00
navi fn url::open 'https://github.com/pulls?&q=author:<user>+is:open+is:pr'
# Checkout a branch from a fork
git fetch origin pull/<pr_number>/head:pr/<pr_number> \
&& git checkout pr/<pr_number>
2019-09-24 12:42:23 +00:00
# Add a new module
2019-10-14 13:51:58 -03:00
git submodule add <repository> <path>
2019-09-24 12:42:23 +00:00
# Update module
git submodule update --init
# Update module without init
git submodule update
# Pull all submodules
git submodule foreach git pull origin master
# Update all submodules
git submodule update --init --recursive
2019-09-21 20:16:20 -03:00
$ branch: git branch | awk '{print $NF}'