GIT

Learn version control basics, tracking code changes and
collaborating efficiently using Git commands and workflows.

Git Basics and Core Commands

1. git init

Initializes a new Git repository in the current directory.

git init
2. git clone

Clones an existing repository from a remote server (like GitHub).

git clone https://github.com/user/project.git
3. git status

Displays the status of the working directory and staging area.

git status
4. git add

Adds files to the staging area, preparing them for a commit.

git add filename.txt
git add . // Add all changes
5. git commit

Records changes to the repository with a message.

git commit -m "Added login feature"
6. git log

Shows the commit history of the repository.

git log
7. git diff

Shows the differences between files in the working directory and the last commit.

git diff
git diff filename.txt
8. git branch

Lists, creates, or deletes branches.

git branch
git branch new-feature
9. git checkout

Switches to another branch or commit.

git checkout main
git checkout -b new-feature
10. git merge

Merges changes from one branch into the current branch.

git merge new-feature

Git Remote and Collaboration Commands

11. git remote

Manages remote repository connections.

git remote -v // Show remotes
git remote add origin https://github.com/user/repo.git
12. git push

Uploads local commits to a remote repository.

git push origin main
git push -u origin main // First push sets upstream
13. git pull

Fetches and merges changes from the remote to the current branch.

git pull origin main
14. git fetch

Downloads objects and references from another repository but doesn’t merge.

git fetch origin
15. git reset

Moves the HEAD and optionally modifies the index and working directory.

git reset --soft HEAD~1 // Keep changes staged
git reset --hard HEAD~1 // Discard changes
16. git revert

Creates a new commit that reverses the effects of a previous commit.

git revert abc123
17. git stash

Temporarily saves uncommitted changes.

git stash
git stash pop
18. git tag

Used to label specific points in history as important (like version releases).

git tag v1.0
git tag -a v1.1 -m "Release version 1.1"
19. git show

Displays information about a Git object (commit, tag, etc.).

git show v1.0
git show abc123
20. git config

Sets configuration values like username and editor preferences.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Advanced Git Commands and Utilities

21. git rebase

Reapplies commits from one branch onto another, creating a linear history.

git checkout feature
git rebase main
22. git cherry-pick

Applies a single commit from one branch onto the current branch.

git cherry-pick abc123
23. git blame

Shows who last modified each line of a file.

git blame app.js
24. git clean

Removes untracked files from the working directory.

git clean -f // Remove files
git clean -fd // Remove files and directories
25. git describe

Describes the current commit using the most recent tag.

git describe --tags
26. git archive

Creates an archive (e.g., .zip or .tar) of files from a repository.

git archive -o latest.zip HEAD
27. .gitignore File

Specifies intentionally untracked files to ignore.

# .gitignore
node_modules/
.env
*.log
28. git shortlog

Summarizes `git log` output by author and commit count.

git shortlog -sn
29. git grep

Searches for strings in tracked source files.

git grep "function"
30. git bisect

Used to find which commit introduced a bug using binary search.

git bisect start
git bisect bad
git bisect good abc123
git bisect reset

Git Reference Links

1. Official Git Documentation

The most comprehensive and authoritative guide for Git commands and usage.

https://git-scm.com/doc

2. Git Book (Pro Git)

A free, complete book on Git by Scott Chacon and Ben Straub (officially supported by Git SCM).

https://git-scm.com/book/en/v2

3. GitHub Git Cheat Sheet

Handy cheat sheet of frequently used Git commands.

https://education.github.com/git-cheat-sheet-education.pdf

4. Atlassian Git Tutorials

Friendly guides, tutorials, and visuals for Git beginners and intermediates.

https://www.atlassian.com/git/tutorials

5. W3Schools Git Tutorial

Easy-to-follow Git instructions and command examples for learners.

https://www.w3schools.com/git/

6. Git Explorer (Interactive Tool)

A fun and fast way to learn Git commands interactively.

https://gitexplorer.com/