% git # Set global git user name git config --global user.name # Set global git user email git config --global user.email # Initializes a git repository git init # Clone a git repository git clone -b # Shallow clone with depth 1 with all branches and submodules git clone --depth=1 --no-single-branch --recurse-submodules # Rebase upstream master into local/origin master (use if people don't clone your repository) git fetch git checkout master git rebase /master git fetch --unshallow origin git push -f origin master # Merge upstream master into local/origin master (use if people clone your repository) git fetch git checkout master git merge /master git fetch --unshallow origin git push -f origin master # View all available remote for a git repository git remote --verbose # Adds a remote for a git repository git remote add # Renames a remote for a git repository git remote rename # Remove a remote for a git repository git remote remove # Checkout to branch git checkout # Displays the current status of a git repository git status # Displays unstaged changes for file cd ; \ git diff # Stage single or multiple files cd ; \ git add ; # Stage all files in project git add -A # Create commit for staged files git commit -m "" # Create backdated commit for staged files git commit --date=" days ago" -m "" # Pushes committed changes to remote repository git push -u # Pushes changes to a remote repository overwriting another branch git push : # Overwrites remote branch with local branch changes git push -f # Pulls changes to a remote repo to the local repo git pull --ff-only # Merges changes on one branch into current branch git merge # Abort the current conflict resolution process, and try to reconstruct the pre-merge state. git merge --abort # 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 # See all open pull requests of a user on Github navi fn url::open 'https://github.com/pulls?&q=author:+is:open+is:pr' # Checkout a branch from a fork git fetch origin pull//head:pr/ \ && git checkout pr/ # Add a new module git submodule add # 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 # Skip git hooks git commit --no-verify # Create new branch from current HEAD git checkout -b # Remove commits from local repository (destroy changes) git reset --hard HEAD~ # Remove commits from local repository (keep changes) git reset --soft HEAD~ $ branch: git branch | awk '{print $NF}' $ toplevel_directory: git rev-parse --show-toplevel $ unstaged_files: git status --untracked-files=no -s --porcelain | awk '{print $NF}' --- --multi true $ changed_files: git status --untracked-files=all -s --porcelain | awk '{print $NF}' --- --multi true