| Term | Definition |
|---|---|
| Version Control | System that records changes to files over time, enabling retrieval of specific versions later |
| Repository (Repo) | Storage location containing project files and complete version history |
| Commit | Snapshot of changes with unique identifier (SHA-1 hash), message, author, and timestamp |
| Working Directory | Local folder containing current versions of project files |
| Staging Area (Index) | Intermediate area where changes are prepared before committing |
| Branch | Parallel version of repository allowing independent development lines |
| HEAD | Pointer referencing current branch and most recent commit |
| Command | Purpose |
|---|---|
| git config --global user.name "Name" | Set username for all repositories |
| git config --global user.email "email" | Set email for all repositories |
| git config --list | Display all configuration settings |
| Command | Function |
|---|---|
| git init | Initialize new Git repository in current directory |
| git clone [url] | Copy remote repository to local machine |
| Command | Function |
|---|---|
| git status | Show working directory and staging area status |
| git add [file] | Stage specific file for commit |
| git add . | Stage all changed files in current directory |
| git add -A | Stage all changes (new, modified, deleted) in entire repository |
| git commit -m "message" | Commit staged changes with descriptive message |
| git commit -am "message" | Stage and commit all tracked files in one command |
| Command | Function |
|---|---|
| git log | Display commit history with full details |
| git log --oneline | Show condensed commit history (one line per commit) |
| git log --graph | Display branch and merge history visually |
| git diff | Show unstaged changes between working directory and staging area |
| git diff --staged | Show differences between staging area and last commit |
| git show [commit] | Display details and changes of specific commit |
| Command | Function |
|---|---|
| git checkout -- [file] | Discard changes in working directory (restore from staging area) |
| git reset [file] | Unstage file while keeping working directory changes |
| git reset --soft [commit] | Move HEAD to commit, keep staging area and working directory unchanged |
| git reset --mixed [commit] | Move HEAD to commit, reset staging area, keep working directory |
| git reset --hard [commit] | Move HEAD to commit, reset staging area and working directory (destructive) |
| git revert [commit] | Create new commit that undoes changes from specified commit |
| Command | Function |
|---|---|
| git branch | List all local branches (current branch marked with *) |
| git branch [name] | Create new branch without switching to it |
| git checkout [branch] | Switch to specified branch |
| git checkout -b [branch] | Create new branch and switch to it immediately |
| git branch -d [branch] | Delete branch (only if merged) |
| git branch -D [branch] | Force delete branch (even if unmerged) |
| git branch -m [old] [new] | Rename branch |
| Command | Function |
|---|---|
| git merge [branch] | Merge specified branch into current branch |
| git merge --no-ff [branch] | Create merge commit even for fast-forward merges |
| git merge --abort | Cancel merge and return to pre-merge state |
| Type | Description |
|---|---|
| Fast-Forward | Branch pointer moves forward when no divergent commits exist |
| Three-Way Merge | Creates merge commit combining changes from two divergent branches |
| Merge Conflict | Occurs when same file section modified in both branches; requires manual resolution |
| Command | Function |
|---|---|
| git rebase [branch] | Move current branch commits to tip of specified branch |
| git rebase -i [commit] | Interactive rebase allowing commit editing, squashing, reordering |
| git rebase --continue | Continue rebase after resolving conflicts |
| git rebase --abort | Cancel rebase and return to original state |
| Merge | Rebase |
|---|---|
| Preserves complete history | Creates linear history |
| Creates merge commits | No merge commits |
| Safe for public branches | Never rebase public branches |
| More complex history graph | Cleaner, simpler history |
| Command | Function |
|---|---|
| git remote | List remote repository names |
| git remote -v | List remotes with URLs |
| git remote add [name] [url] | Add new remote repository |
| git remote remove [name] | Remove remote repository |
| git remote rename [old] [new] | Rename remote |
| Command | Function |
|---|---|
| git fetch [remote] | Download remote changes without merging |
| git pull [remote] [branch] | Fetch and merge remote changes (fetch + merge) |
| git pull --rebase | Fetch and rebase local commits on top of remote |
| git push [remote] [branch] | Upload local commits to remote repository |
| git push -u [remote] [branch] | Push and set upstream tracking branch |
| git push --force | Overwrite remote history (use with caution) |
| git push --delete [remote] [branch] | Delete remote branch |
| Command | Function |
|---|---|
| git branch -r | List remote branches |
| git branch -a | List all branches (local and remote) |
| git checkout -b [branch] [remote]/[branch] | Create local branch tracking remote branch |
| git branch -vv | Show tracking branch information |
| Step | Action |
|---|---|
| 1. Fork | Create personal copy of repository on GitHub |
| 2. Clone | Download forked repository to local machine |
| 3. Branch | Create feature branch for changes |
| 4. Commit | Make and commit changes locally |
| 5. Push | Upload changes to forked repository |
| 6. Pull Request | Request original repository to merge changes |
| Command | Function |
|---|---|
| git remote add upstream [url] | Add original repository as upstream remote |
| git fetch upstream | Fetch changes from original repository |
| git merge upstream/main | Merge upstream changes into local branch |
| git push origin main | Update fork with upstream changes |
| Command | Function |
|---|---|
| git stash | Save uncommitted changes temporarily |
| git stash save "message" | Stash with descriptive message |
| git stash list | Show all stashed changes |
| git stash apply | Reapply most recent stash |
| git stash apply stash@{n} | Apply specific stash |
| git stash pop | Apply and remove most recent stash |
| git stash drop stash@{n} | Delete specific stash |
| git stash clear | Delete all stashes |
| Command | Function |
|---|---|
| git tag | List all tags |
| git tag [name] | Create lightweight tag at current commit |
| git tag -a [name] -m "message" | Create annotated tag with metadata |
| git tag [name] [commit] | Tag specific commit |
| git push origin [tag] | Push specific tag to remote |
| git push origin --tags | Push all tags to remote |
| git tag -d [name] | Delete local tag |
| Command | Function |
|---|---|
| git cherry-pick [commit] | Apply changes from specific commit to current branch |
| git cherry-pick [commit1] [commit2] | Apply multiple commits |
| git cherry-pick --continue | Continue after resolving conflicts |
| git cherry-pick --abort | Cancel cherry-pick operation |
| Command | Function |
|---|---|
| git submodule add [url] [path] | Add repository as submodule |
| git submodule init | Initialize submodules in repository |
| git submodule update | Fetch and checkout submodule commits |
| git clone --recursive [url] | Clone repository including all submodules |
| Pattern | Meaning |
|---|---|
| *.log | Ignore all .log files |
| temp/ | Ignore entire temp directory |
| !important.log | Exception: do not ignore this file |
| **/logs | Ignore logs directory anywhere in repository |
| doc/*.txt | Ignore .txt files in doc directory only |
| doc/**/*.pdf | Ignore .pdf files in doc and all subdirectories |
| Branch Type | Purpose |
|---|---|
| main/master | Production-ready code |
| develop | Integration branch for features |
| feature/[name] | New feature development |
| bugfix/[name] | Bug fixes |
| hotfix/[name] | Critical production fixes |
| release/[version] | Release preparation |
| Problem | Solution |
|---|---|
| Committed to wrong branch | git reset HEAD~1 (undo commit), checkout correct branch, recommit |
| Need to change last commit | git commit --amend (modify most recent commit) |
| Accidentally deleted file | git checkout HEAD [file] (restore from last commit) |
| Merge conflict | Edit conflicted files, git add [file], git commit |
| Pushed wrong code | git revert [commit] (safer) or git reset + git push --force (risky) |
| Detached HEAD state | git checkout [branch] to return to branch |
| Command | Information |
|---|---|
| git status | Current branch, staged/unstaged changes |
| git log --all --graph | Complete branch structure visualization |
| git reflog | History of HEAD movements (useful for recovery) |
| git ls-files | List all tracked files |
| Command | Creates Alias |
|---|---|
| git config --global alias.co checkout | git co (for checkout) |
| git config --global alias.br branch | git br (for branch) |
| git config --global alias.ci commit | git ci (for commit) |
| git config --global alias.st status | git st (for status) |
| git config --global alias.unstage 'reset HEAD --' | git unstage (to unstage files) |
| git config --global alias.last 'log -1 HEAD' | git last (show last commit) |