A comprehensive single-page reference covering Git fundamentals, GitHub workflows, and IntelliJ IDEA integration for everyday development.
Git is a distributed version control system that tracks changes in your codebase. Every developer has a full copy of the repository, including its entire history. Changes flow through three local areas before reaching the remote.
The Git Data Flow
git add
→
git commit
→
git push
→
Your actual project files on disk. This is where you edit code. Files here can be untracked (new) or modified (changed since last commit).
A holding zone where you prepare changes for the next commit. Use
git add to move changes here. Think of it as a
"draft" of your next commit.
Your local .git directory containing the full commit
history. When you git commit, a snapshot is saved
here with a unique SHA hash.
The shared repository on GitHub (or another host). Use
git push to upload and git pull to
download changes from the team.
a1b2c3d). You can always reference any commit by its
hash, branch name, or tag.
# Set your identity (required for commits)
git config –global user.name “Your Name”
git config –global user.email “you@example.com”
# Set default branch name
git config –global init.defaultBranch main
# View all config
git config –list
# Create a new local repo
git init
# Clone an existing remote repo
git clone https://github.com/org/repo.git
# Clone into a specific folder
git clone https://github.com/org/repo.git my-folder
# Check status of working directory
git status
# Stage specific files
git add file1.java file2.java
# Stage all changes
git add .
# Commit with a message
git commit -m “feat: add user authentication endpoint”
# Push to remote
git push origin feature/my-branch
# Pull latest changes
git pull origin main
# View commit log
git log –oneline –graph –all
# Show changes in working directory
git diff
# Show staged changes
git diff –staged
# Show a specific commit
git show a1b2c3d
# Who changed each line?
git blame src/Main.java
Branches let you work on features, fixes, or experiments in isolation. They're lightweight pointers to commits — creating one is nearly instant.
# List all branches (* = current)
git branch
# List remote branches
git branch -r
# Create a new branch
git branch feature/login-page
# Switch to a branch
git checkout feature/login-page
# Create AND switch (shorthand)
git checkout -b feature/login-page
# Modern alternative (Git 2.23+)
git switch -c feature/login-page
# Delete a local branch
git branch -d feature/login-page
# Force delete (unmerged branch)
git branch -D feature/login-page
# Delete a remote branch
git push origin –delete feature/login-page
New functionalityfeature/user-authfeature/JIRA-123-payment
Bug fixesbugfix/null-pointer-fixbugfix/JIRA-456-login
Urgent production fixeshotfix/security-patchhotfix/critical-crash
# Switch to the target branch
git checkout main
# Merge the feature branch
git merge feature/login-page
# Merge with no fast-forward (always create merge commit)
git merge –no-ff feature/login-page
# Abort a merge in progress
git merge –abort
# Rebase current branch onto main
git checkout feature/login-page
git rebase main
# Interactive rebase (squash, reorder, edit commits)
git rebase -i HEAD~3
# Abort a rebase in progress
git rebase –abort
# Continue after resolving conflicts
git rebase –continue
Conflicts happen when two branches modify the same lines. Git marks them in the file:
<<<<<<< HEAD
# your changes on the current branch
incoming changes from the other branch
>>>>>>> feature/login-page
# After manually editing the file to resolve:
git add resolved-file.java
git commit
GitHub Flow is a lightweight, branch-based workflow ideal for teams practicing continuous delivery.
GitHub Flow — Step by Step
Branch off main with a descriptive name:
git checkout -b feature/add-notifications
Write code, stage changes with git add, and commit
with clear messages following conventional commits.
Push your branch:
git push origin feature/add-notifications
On GitHub, open a PR against main. Add a description,
link related issues, and request reviewers.
Teammates review your code. CI pipelines run automated tests. Address feedback with additional commits.
Once approved, merge the PR (squash merge recommended for clean history). Delete the feature branch.
# View remotes
git remote -v
# Add a remote
git remote add upstream https://github.com/original/repo.git
# Fetch all remote branches (without merging)
git fetch –all
# Pull = fetch + merge
git pull origin main
# Pull with rebase (cleaner history)
git pull –rebase origin main
# Push and set upstream tracking
git push -u origin feature/my-branch
git fetch regularly to stay aware of remote changes
without modifying your working directory. It's always safe.
Use conventional commit format:feat: add email notification servicefix: resolve null pointer in UserDAO
Explain what changed and why. Link JIRA tickets. Include screenshots for UI changes. List any breaking changes.
Safe
Preserves all commits.
Creates a merge commit. Full history retained.
Recommended
Combines all
PR commits into one. Clean main branch history.
Advanced
Replays commits
on top of main. Linear history, no merge commit.
# Create a PR
gh pr create –title “feat: add notifications” –body “Adds email notifications for overdue payments”
# List open PRs
gh pr list
# Check out a PR locally
gh pr checkout 42
# Merge a PR
gh pr merge 42 –squash
| Action | Shortcut | Description |
|---|---|---|
| Commit | Ctrl+K | Open the commit dialog with diff preview |
| Push | Ctrl+Shift+K | Push commits to remote |
| Update Project | Ctrl+T | Pull/fetch latest changes |
| VCS Operations | Ctrl+Shift+` | Quick popup for common Git actions |
| Git Log | Alt+9 | Open the Git log tool window |
| Annotate (Blame) | Right-click gutter | Show who changed each line and when |
| Show Diff | Ctrl+D | Show diff for selected file in commit dialog |
| Rollback Changes | Ctrl+Alt+Z | Revert selected file to last committed state |
| Show History | Right-click → Git → Show History | View full commit history for a file |
| Resolve Conflicts | Git → Resolve Conflicts | Open the 3-way merge tool |
Click the branch indicator in the bottom-right corner, or use Ctrl+Shift+` → Branches.
Edit files normally. IntelliJ tracks changes automatically. Modified files appear in the Commit tool window (Alt+0).
Press Ctrl+K. Review diffs inline, select files to include, write your commit message, and hit Commit.
Press Ctrl+Shift+K to push. You can also "Commit and Push" in one step from the commit dialog.
IntelliJ shows colored markers in the editor gutter:
Click any gutter marker to see the original code and quickly revert individual changes.
IntelliJ lets you organize uncommitted changes into named changelists. Useful when working on multiple things at once:
Stashing temporarily shelves your uncommitted changes so you can switch branches or pull updates without committing half-done work.
# Stash all uncommitted changes
git stash
# Stash with a descriptive message
git stash push -m “WIP: halfway through login refactor”
# Stash including untracked files
git stash -u
# List all stashes
git stash list
# Apply most recent stash (keeps it in stash list)
git stash apply
# Apply and remove from stash list
git stash pop
# Apply a specific stash
git stash apply stash@{2}
# View stash contents
git stash show -p stash@{0}
# Drop a specific stash
git stash drop stash@{1}
# Clear all stashes
git stash clear
Git provides several ways to undo changes, ranging from safe to destructive:
# Discard changes in a specific file
git checkout – file.java
# Modern alternative (Git 2.23+)
git restore file.java
# Discard ALL unstaged changes
git restore .
# Unstage a file (keep changes in working dir)
git reset HEAD file.java
# Modern alternative
git restore –staged file.java
# Change the last commit message
git commit –amend -m “fix: corrected commit message”
# Add forgotten files to last commit
git add forgotten-file.java
git commit –amend –no-edit
# Revert a specific commit (creates a new "undo" commit)
git revert a1b2c3d
# Revert without auto-committing
git revert –no-commit a1b2c3d
This is the safest way to undo a pushed commit — it doesn’t rewrite history.
# Soft reset: undo commit, keep changes staged
git reset –soft HEAD~1
# Mixed reset (default): undo commit, keep changes unstaged
git reset HEAD~1
# Hard reset: undo commit AND discard all changes
git reset –hard HEAD~1
# Reset to a specific commit
git reset –hard a1b2c3d
git reset –hard permanently destroys uncommitted
changes. Use with extreme caution. If you’ve already pushed, use
git revert instead.
# Preview what would be deleted
git clean -n
# Delete untracked files
git clean -f
# Delete untracked files AND directories
git clean -fd
Git Flow is a structured branching model designed for projects with scheduled releases. It defines specific branch types and their roles.
Production-ready code. Every commit here is a release. Tagged with version numbers.
Integration branch for features. Always reflects the latest delivered development changes.
Branch off develop, merge back into
develop. One feature per branch.
Branch off develop when ready to release. Bug fixes
only. Merges into both main and develop.
Branch off main for urgent production fixes. Merges
into both main and develop.
Tag every release on main:
git tag -a v1.0.0 -m "Release 1.0.0"
# Start a new feature
git checkout develop
git checkout -b feature/user-profile
# Finish a feature (merge back to develop)
git checkout develop
git merge –no-ff feature/user-profile
git branch -d feature/user-profile
# Start a release
git checkout develop
git checkout -b release/1.2.0
# Finish a release
git checkout main
git merge –no-ff release/1.2.0
git tag -a v1.2.0 -m “Release 1.2.0”
git checkout develop
git merge –no-ff release/1.2.0
# Hotfix
git checkout main
git checkout -b hotfix/critical-fix
# … fix the issue …
git checkout main
git merge –no-ff hotfix/critical-fix
git tag -a v1.2.1
git checkout develop
git merge –no-ff hotfix/critical-fix
Follow the Conventional Commits standard for clear, parseable history:
type(scope): short description
Optional body with more detail.
Explain WHAT changed and WHY, not HOW.
Refs: JIRA-123
feat: New feature
fix: Bug fix
refactor: Code
restructure
docs: Documentation
chore: Maintenance
test: Adding tests
.gitignore properly# IntelliJ IDEA
.idea/
*.iml
*.iws
out/
# Build output
target/
build/
*.class
*.jar
*.war
# Environment & secrets
.env
*.properties.local
application-local.yml
# OS files
.DS_Store
Thumbs.db
# Logs
*.log
logs/
git config --global alias.st "status -sb"
git config –global alias.co “checkout”
git config –global alias.br “branch”
git config –global alias.ci “commit”
git config –global alias.lg “log –oneline –graph –all –decorate”
git config –global alias.last “log -1 HEAD –stat”
git config –global alias.unstage “restore –staged”
| Task | Command | Safety |
|---|---|---|
| See what changed | git status |
Safe |
| Stage everything | git add . |
Safe |
| Commit changes | git commit -m "msg" |
Safe |
| Push to remote | git push origin branch |
Safe |
| Pull latest | git pull origin main |
Safe |
| Create branch | git checkout -b name |
Safe |
| Stash changes | git stash |
Safe |
| Undo last commit (keep changes) | git reset --soft HEAD~1 |
Caution |
| Revert a pushed commit | git revert <sha> |
Safe |
| Nuke everything | git reset --hard HEAD~1 |
Destructive |
git reflog is your safety net. It
records every HEAD movement, so you can recover from almost any
mistake within 30 days.