- Git Flight Rules The guide for when things go wrong
- Git Tips Most commonly used git tips and tricks
- Git Visual Reference Easily see what a command affects
<remote>
= remote repository name. Usually origin or upstream
- Fork project
git clone <your forked repository url> .
create local repository in current directory and checkout master branchgit branch <new branch name>
create a branch for changes you will performgit checkout <new branch name>
switch working directory files to new branchgit add ...
mark changed files and new files you wish to commit to local repositorygit commit -m <message>
save a verion of all added files in the local repositorygit push -u <remote> <new branch name>
upload new branch to remote repositorygit push
*After branch is pushed, 'git push' can be used for all other updates- Create a pull request from the github page to ask original project owner to merge changes from your forked project.
Starting with a project that has aleady been cloned
git fetch origin
update your local copy of remote branches. Does not change any local branches- This is needed to stay in sync with changes others are doing in the remote repository
git merge <other branch>
execute from your local working branch to merge in changes from another branch
Starting with a project that has aleady been cloned
git fetch remote
update your local copy of remote branches. Does not change any local branches- This is needed to stay in sync with changes others are doing in the remote repository
git merge <other branch>
execute from your local working branch to merge in changes from another branch
git merge --squash <other branch>
take all commits from another branch and merge into current branch as single commit
- List files changed, merges, conflicts and general info
git status
- List remote names and urls
git remote -v
- List all branches local and remote
git branch -avv
- List information from remote by querying remote
git remote show origin
- List all remote references, tags, branches
git ls-remote
- List changed files between branches or commits
git diff --stat <branch1>..<branch2>
- Delete branch on the remote repository
git push <remote> :<remote branch>
push nothing from local to remote, which deletes remote branch
- Delete multiple obsolete tracking branches
git fetch <remote> --prune
How to undo (almost) anything with Git
- Restore deleted branch or lost commit
git reflog
use to find commit idgit checkout -b branch-name <commit id>
creates new branch from commit
- Undo change already pushed
git revert <SHA>
creates a new commit that is the inverse of the given SHA. Does not alter history
- Go back to previous version of file(s)
git checkout -- <filename>
replace with last committed version
- Remove already tracked files added to
.gitignore
git rm -r --cached .
git add .
git tag <tagname>
create a tag on local repositorygit push <remote> tag
push tag to remote repository
- Remotes and trackingb information stored in
.git/config
- Show location of all configs
git config --list --show-origin
- Useful log alias for config
[alias] lg = log --graph --pretty=format:'%C(yellow)%h%Creset%C(red)%d%Creset %C(cyan)(%cr)%Creset %C(green)%aN%Creset %s'
- set global location using
npm config set prefix ~/.local