This is not a tutorial on how to use git.
It's meant as a quick way to look up git commands. Please do not use these commands if you're just learning to use git;
kindly follow these links at the bottom of this post to get Git guides and tutorials.
Git Quick Commands Listing
Git Configuration
Add your name and email (baked into each commit made):
Configure text editor to use (e.g. to use vim)
Adding colors
In case you have a GPG key you’d like used to sign your commits you can add it
Listing all configurations set
Other useful configurations
Git Basics
Initialize a repository
Cloning a remote repository
Adding files to repository
Listing files and tracking status
Removing a file from tracking
To prevent tracking of files; add the file or directory to the .gitignore file (each file/directory on a new line).
Committing
Resetting and Reverting Repo
Revert to previous commit (graceful - does not delete history)
Undo changes you've made to a file i.e. and replace it with the HEAD version.
Reset to previous state: Do not use if already commited to shared remote
Re-clone from a remote repository; will loose changes not in the remote. (e.g if local git corrupt)
Git Branches
Git Branch Naming Conventions
Use grouping tokens (short words) at the beginning of branch names. e.g. wip(work in progress), feat(feature), fix(bug fix), temp(temporary/throaway branch)
Separate branch name parts using slashes i.e. wip/material-design, fix/authflow
Do not start branch names with numbers, git may confuse them for SHA-1's
Avoid long branch-names
</li>
</ul>
Git merge
Before merging, checkout to branch you want to merge to:
Merge remote branch
Rewriting Git History
NOTE: Do not rewrite public commits/history
Git Rebase
Moving a branch to a new base commit (an ID, a branch name, a tag, or a relative reference to HEAD)
Interactive Rebasing
Changing multiple commit messages. git rebase -i 9fceb02(9fceb02 is an example ID)
provides an interactive text editor for modifying all commits after the base specified (eg 9fceb02)
Other Interactive Rebase Commands:
p, pick - use commit
r, reword - use commit, but edit the commit message
e, edit - use commit, but stop for amending
s, squash - use commit, but meld into previous commit
f, fixup - like "squash", but discard this commit's log message
x, exec - run command (the rest of the line) using shell
Interactive Rebasing Tips
To reorder commits, reorder the lines; they are executed from top to bottom. If you remove a line, THAT COMMIT WILL BE LOST However, if you remove everything, the rebase will be aborted. Empty commits are commented out
Working with Remotes
Adding remote - Connecting local repo with a remote repo (for example a repo on github)
Stashing
Stash - Store modified tracked files and staged changes on a stach for reapplying later