main
branch is always used in production.
Tutorials:
Command | Description |
---|---|
git checkout -b new_branch |
New branch. |
git checkout -- . |
Discard changes in the working directory and revert it to the state of the last commit. |
git pull --rebase |
- |
rm -rfv .git |
- |
git switch daves_branch |
Pull my remote branch. |
git rm anyFile --cached , then commit |
Forcing files into .gitignore |
| `` | |
Commands used for creating, initializing, cloning, and configuring Git repositories. Examples include git init, git clone, git config.
Command | Description |
---|---|
git init |
Create an empty Git repository or reinitialize an existing one |
git clone |
Clone a repository into a new directory |
git config |
Get and set repository or global options |
git remote |
Manage set of tracked repositories |
git fetch |
Download objects and refs from another repository |
git pull |
Fetch from and integrate with another repository or a local branch |
git push |
Update remote refs along with associated objects |
git archive |
Create an archive of files from a named tree |
git submodule |
Initialize, update or inspect submodules |
git worktree |
Manage multiple working trees |
git fetch -v --dry-run |
check if pull needed in Git |
git config --get remote.origin.url |
display information |
git remote show origin |
full information |
Commands used for creating, listing, switching, merging, and deleting branches. Examples include git branch, git checkout, git merge.
Command | Description |
---|---|
git branch |
List, create, or delete branches |
git checkout |
Switch branches or restore working tree files |
git merge |
Join two or more development histories together |
git rebase |
Reapply commits on top of another base tip |
git cherry-pick |
Apply the changes introduced by some existing commits |
git revert |
Revert some existing commits |
git reset |
Reset current HEAD to the specified state |
git tag |
Create, list, delete or verify a tag object signed with GPG |
git describe |
Give an object a human readable name based on an available ref |
git reflog |
Manage reflog information |
Commands used for adding, committing, and tracking changes to the repository. Examples include git add, git commit, git status.
Command | Description |
---|---|
git add |
Add file contents to the index |
git commit |
Record changes to the repository |
git diff |
Show changes between commits, commit and working tree, etc |
git status |
Show the working tree status |
git log |
Show commit logs |
git blame |
Show what revision and author last modified each line of a file |
git bisect |
Use binary search to find the commit that introduced a bug |
git grep |
Print lines matching a pattern |
git stash |
Stash the changes in a dirty working directory away |
git cherry |
Find commits yet to be applied to upstream |
Commands used for undoing changes to the repository. Examples include git revert, git reset.
Command | Description |
---|---|
git reset |
Reset current HEAD to the specified state |
git checkout |
Switch branches or restore working tree files |
git revert |
Revert some existing commits |
git clean |
Remove untracked files from the working tree |
git reflog |
Manage reflog information |
git revert --abort |
Cancel the revert operation and reconstruct the original HEAD |
git reset --soft |
Uncommit changes, changes are left staged (index). Scope: Head only, index and working directory unchanged |
git reset --mixed |
Default value. Uncommit + unstage changes. Changes are left in working tree. Scope: Index + Head, changed |
git reset --hard |
Reset the current branch to the specified commit and discard all changes. Uncommit + unstage + delete changes. Nothing is left. Scope: Working directory + Index + HEAD, all changed |
git checkout -b <new-branch> <start-point> |
Create a new branch and switch to it |
git reset HEAD <file> |
Remove the specified file from the staging area |
git revert -m <parent-number> <commit> |
Revert a merge commit |
Commands used for temporarily storing changes and cleaning up the repository. Examples include git stash, git clean.
Command | Description |
---|---|
git stash |
Stash the changes in a dirty working directory away |
git stash list |
List all stashed changesets |
git stash apply |
Apply the changes recorded in the specified stash |
git stash pop |
Apply and remove the changes recorded in the most recent stas |
git stash drop |
Remove the changes recorded in the specified stash |
git stash clear |
Remove all stashed entries |
git clean |
Remove untracked files from the working tree |
git clean -f |
Remove untracked files from the working tree forcefully |
git clean -d |
Remove untracked directories in addition to untracked files |
git clean -x |
Remove only files ignored by Git |
Commands used for collaborating with other developers on a Git project. Examples include git push, git pull, git fetch.
Command | Description |
---|---|
git clone |
Clone a repository into a new directory |
git push |
Update remote refs along with associated objects |
git pull |
Fetch from and integrate with another repository or a local branch |
git fetch |
Download objects and refs from another repository |
git remote |
Manage set of tracked repositories |
git branch -r |
List the remote branches |
git merge |
Join two or more development histories together |
git rebase |
Forward-port local commits to the updated upstream head |
git tag |
Create, list, delete or verify a tag object signed with GPG |
git cherry-pick |
Apply the changes introduced by some existing commits |
- cherry-pick: https://stackoverflow.com/a/9339460/7389293
Commands used for creating, listing, and deleting tags in a Git repository.
Command | Description |
---|---|
git tag |
Create, list, delete or verify a tag object signed with GPG |
git tag -l |
List tags |
git tag -a |
Create an annotated tag object |
git tag -d |
Delete a tag object |
git describe |
Describe the commit that is the ancestor of the current revision a specified tag |
git push --tags |
Push tags to a remote repository |
git show |
Show information about a commit, tag, or tree |
git log --tags |
Show commits that are referenced by refs/tags |
git rev-list --tags |
List commits that are referenced by refs/tags |
git push <remote> <tagname> |
Push a single tag to a remote repository |
Other commands that don't fit into the above categories. Examples include git log, git diff, git grep.
Command | Description |
---|---|
git status |
Show the working tree status |
git config |
Get and set repository or global options |
git log |
Show commit logs |
git diff |
Show changes between commits, commit and working tree, etc |
git grep |
Print lines matching a pattern |
git blame |
Show what revision and author last modified each line of a file |
git mv |
Move or rename a file, a directory, or a symlink |
git rm |
Remove files from the working tree and from the index |
git archive |
Create a tar or zip archive of the contents of a tree |
git help |
Display help information about Git |
Command | Description |
---|---|
git diff |
Compares changes: locally working/staging |
git diff master origin/master |
Compares changes: local/remote |
git diff --staged |
Compares changes: staging/repository |
git diff --color-words |
Color changes made in a diff |
Command | Description |
---|---|
git log |
Logs all commit history |
git log -1 |
Logs last one commit |
git log -n 5 |
|
git log --oneline |
|
git log --grep="bug" |
prints out any commit with the string 'bug' |
git show |
Shows last commit and content, add as last parameter what you want to find, let's say the SHA |
git config --global <variable> <value>
Variable | Value |
---|---|
user.name |
"UserName" |
user.email |
"[email protected]" |
alias.lg |
"log --oneline --decorate --all --graph" |
alias.s |
"status -s" |
`` | `` |
Command | Description |
---|---|
git config --list --show-origin |
|
git config --local --list |
Repository level |
git config --global --list |
Global Git, at OS user level |
git config --system --list |
Entire machine, all users and repositories |
- Lowercase and Punctuation: Do not end in punctuation. All lowercase.
- Mood: Imperative in subject line, which gives the tone you are giving an order. Presente tense.
- Type of Commit: Specify the type of commit.
- Length: First line no more than 50 characters. Body restricted to 72 characters. Separate subject from the body with a blank line.
- Content: Be direct, try to eliminate filler words and phrases. Use the body to explain what and why vs. how.
build
– changes that affect the build system or external dependencieschore
– changes that do not relate to a fix or feature and don't modify src or test files (for example updating dependencies)ci
– continuous integration relateddocs
– updates to documentation such as a the README or other markdown filesfeat
– a new feature is introduced with the changesfix
– a bug fix has occurred. Add tiker number when possibleperf
– code change that improves performancerefactor
– refactored code that neither fixes a bug nor adds a featurestyle
– code formatting such as white-space, missing semi-colons, and so on.test
– including new or correcting previous testsrevert
– reverts a previous commitupdate
– What is this for?
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
fix: fix foo to enable bar
This fixes the broken behavior of the component by doing xyz.
BREAKING CHANGE
Before this fix foo wasn't enabled at all, behavior changes from <old> to <new>
Closes D2IQ-12345
feat: improve performance with lazy load implementation for images
chore: update npm dependency to latest version
fix: bug preventing users from submitting the subscribe form
update: incorrect client phone number within footer body per client request
fixed bug on landing page
Changed style
oops
I think I fixed it this time?
'empty commit messages'
- How to Write Better Git Commit Messages – A Step-By-Step Guide: https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/
- Patterns for writing better git commit messages: https://dev.to/helderburato/patterns-for-writing-better-git-commit-messages-4ba0
- A Simplified Convention for Naming Branches and Commits in Git: https://dev.to/varbsan/a-simplified-convention-for-naming-branches-and-commits-in-git-il4
Create a new repository on the command line.
git init
git status
git add .
git status
git commit -m 'Commit message'
git branch -M master
git remote add origin https://github.com/username/repository-name.git
git push -u origin master
Push an existing repository from the command line.
git remote add origin https://github.com/username/repository-name.git
git branch -M main
git push -u origin main
git init
git remote add origin https://gitlab.com/username/repository-name.git
git push --set-upstream origin master
git status
git add .
git commit -m 'Commit message'
git push