As I learn my way up to being a proficient contributor to open source, I have kept some of these cheatsheets/resources around to refer in times of need. This list cover mostly the basics and would suffice foundational day-to-day work. I hope you find it useful. Feel free to contribute via issues or pull requests. π
Details
git config --list # see configurations from system, global, local
git config --<level> <setting> <value>
git config --global user.name "<name>" # set transactions' name
git config --global user.email "<email-address>" # set transactions' email
git config --global http.proxy <proxy-address> # set proxy to connect w/ remotes
git init <repository-name>
git clone <url> # from remote
git clone <existing-project-path> <new-project-path> # locally
cd <repository-name>
# cd my-repo
touch <filename>
# touch README.md
# touch .gitignore
<filename>
# app.py
# reference.txt
# *.log # * indicates a wildcard
# *.txt
# build/
echo <filename-to-write>><filename>
# echo *.log > .gitignore # rewrite the file
# echo *.log >> .gitignore # append to the file
git ls-files --other --ignored --exclude-standard
Details
git add <filename>
# git add README.md
# git add . # . indicates all files (except the ones specified in .gitignore)
# git add * # * indicates a wildcard
# git add *.html
# git add *.txt
git clean -n # see untracked files
git clean -f # delete untracked files
git reset <filename> # to file
git reset HEAD # to all files
git reset # to HEAD by default
git checkout -- <filename> # to file
Details
git commit -m "<descriptive-message>"
git commit --amend -m "<new-message>" # ammend commit message
git annotate <filename> # of file since first commit
git diff <commit-hash-1>..<commit-hash-2> # of file between 2 commits
git diff HEAD~<num-1>..HEAD~<num-2>
git checkout <commit-hash> <filename> # of file
git reset <commit-hash>
git revert <commit-hash>
git checkout <current-branch> # to fix detached head
git reset --hard <commit-hash>
Details
git status
git diff # for all files
git diff <filename> # for particular file
git diff --staged
git diff -r HEAD # for all files
git diff -r HEAD <filename> # for particular file
git show <commit-hash>
git show HEAD~<num-commit-before-current>
Details
git branch
git branch <local-branch-name>
git checkout -b <local-branch-name> # then go to that branch
git branch <local-branch-name> <remote-name>/<remote-branch-name> # from remote branch
git checkout -b <local-branch-name> <remote-name>/<remote-branch-name> # this allows you to set local-branch-name on your own
git checkout --track <remote-name>/<remote-branch-name> # this sets the local-branch-name as remote-branch-name
git checkout <local-branch-name>
git diff <branch-1>..<branch-2>
git merge <branch-name> # to current branch
# git merge <branch-name> <another-branch> # to particular branch
git commit -a -m 'message'
git branch -r
git push <remote-name> <local-branch-name>:<remote-branch-name>
git branch -u <remote-name>/<remote-branch-name>
git branch --set-upstream-to <remote-name>/<remote-branch-name>
git branch # view local branch name only
git branch -v # shows latest commit
git branch -vv # shows upstream branch
git push <remote-name> :<remote-branch-name>
git push <remote-name> --delete <remote-branch-name>
git branch -d [local-branch-name]
git checkout better_branch
git merge --strategy=ours master # keep the content of this branch, but record a merge
git checkout master
git merge better_branch # fast-forward master up to the merge
git checkout <old_name> # go to branch to rename
git branch -m <new_name> # rename the branch
git push origin --delete <old_name> # delete the <old_name> remote branch
git push origin -u <new_name> # push the <new_name> local branch & reset the upstream branch
Details
git push <remote-name> <remote-branch-name>
# git push origin master
git remote add <remote-name> <github-link>
# git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
git remote
git clone <clone-url>
git fetch <remote-name>
git fetch --all
git pull <remote-name> # into current branch
git pull <remote-name> <local-name> # into particular branch
git remote add <remote-name> <github-link>
# git remote add myRepo http://github.com/somerepo.git
git remote rm <remote-name>
git chekcout <branch-name>
git branch -u <remote-name>/<branch-name>
git remote -v
git remote set-url <remote-name> <url>
git remote prune <remote-name>
git remote add <remote-name> <primary-repo-url>
git remote set-url --add --push <remote-name> <primary-repo-url> # Re-register remote as a push URL
git remote set-url --add --push <remote-name> <secondary-repo-url> # Add another push URL to this remote
git fetch --all # fetch from multiple remotes
git checkout <branch-name> # checkout to the branch you want to work with
git reset --hard <remote-name>/<branch-name> # switch remotes to access the work done on each one & further work
Details
git stash
git stash list
git stash apply
git stash pop
git stash drop
Details
git rm <filename>
git rm --cached <filename>
git rm -r --cached <folder> # if you want to remove a whole folder, you need to remove all files in it recursively
git mv <filename-original> <file-renamed>
Browse and inspect the evolution of project files
Details
git log
git log --oneline # simplified output
git log -<num-output> <filename> # limit number of output
git log --follow <file>
git diff <first-branch>...<second-branch>
git show <commit-hash>
git checkout <commit-hash>
- How to make Git βforgetβ about a file that was tracked but is now in .gitignore? Stop tracking a file that is currently tracked
- Git LFS: Encountered X file(s) that should have been pointers, but weren't. (reference)
- List of well written READMEs [see]
- GitHub Emojis [see]
- Template to make a good README [see]
- Badges [see]
- Octodex [see]
- LaTeX mathematical symbol embedding [see]
- Explain a license in plain english [see]
- Full guide to choosing a license [see]
- Further license references for open source [see]
- Questions to ask yourself:
- What licenses are already in my software?
- What are the terms of service where my software is hosted?
- Do I want derivatives, additions and distributions to use the same licenses?
- Can others use my software in their own proprietary software?
- Initiator (who logged the call)
- Initiator Extension or Phone
- Date/Time Opened
- Summary Description
- Impact/Importance
- Type (of fault)
- Owner (of system)
- Current Status (open, in process, closed)
- Next Step
- Next Step Date
- Completion Date
- Resolution, development request # or link to vendor support request
- Please refer to CONTRIBUTE.md for details. π
Contributing to Open Source: Tips & Tricks is released under the MIT license.