KEMBAR78
My Git Notes | PDF | Computing | Utility Software
0% found this document useful (0 votes)
7 views4 pages

My Git Notes

Uploaded by

syedfurqanjaved
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

My Git Notes

Uploaded by

syedfurqanjaved
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Here are your notes organized for easy reference:

Basic Git Setup & Initialization

 git config --list — Show current Git configuration


 git init — Initialize a new local Git repository (creates .git folder, aka local repo or
working directory)
 .git — Local repo or working directory

Staging Files

 git add . — Add all files to staging


 git add filename — Add specific file to staging
 git add f1 f2 f3 — Add multiple specific files

Branch & Remote Setup

 git branch -M main — Rename current branch to main


 git remote add origin <url_of_repo> — Add remote repo URL
 git push -u origin main — Push current branch to remote and set upstream

Git Global Configuration

 git config --global user.name "ali" — Set global user name


 git config --global user.email "abc@gmail.com" — Set global user email
 git config --list — List current configuration

Undo & Restore

 Ctrl + Z — (Shell undo, suspend process)


 git restore . — Restore all files to last commit state (before commit)
 git restore filename — Restore specific file to last commit
 git restore --staged filename — Remove file from staging area (move back to
working directory)
 Note: git restore only works before commit
Viewing History & Revert

 git log --oneline — Show short commit history


 git revert <hashcode> — Undo changes introduced by specific commit (creates a
new commit)

Git Reset Variants

1. git reset --soft <commit>


o Move HEAD to commit
o Keep index and working directory unchanged
o Changes after commit stay staged
2. git reset --mixed <commit> (default)
o Move HEAD to commit
o Reset index to commit
o Working directory unchanged
3. git reset --hard <commit>
o Move HEAD to commit
o Reset index and working directory to commit (all changes lost)

Git Config Aliases

 Edit .gitconfig

[alias]
b = branch

 Or set alias via command:


git config alias.b branch
 Usage: git b to show branches

Branch Management & Switching

 git branch NewBranchName — Create branch


 git checkout NewBranchName or git switch NewBranchName — Switch branch
 git checkout -b NewBranchName or git switch -c NewBranchName — Create &
switch branch
 git branch -D branchName — Delete branch
Commit Amend & Cloning

 git commit --amend — Update last commit message or add changes


 git clone url . — Clone repo into current directory

Pull vs Fetch

 git fetch origin — Fetch changes from remote without merging


 git status — Check working directory status
 git merge origin/main — Merge fetched changes
 git pull origin main — Fetch + merge in one command

Differences & Logs

 git diff — Show unstaged changes


 git diff --staged — Show staged changes
 git diff origin/main — Show diff vs remote main branch
 git diff commit1 commit2 — Diff between two commits
 gitk — GUI tool for viewing history

Commit Commands

 git commit -a -m "message" — Commit all tracked files with message


 git commit filename -m "message" — Commit specific file with message

Stashing

 git stash — Save current changes and clean working directory


 git stash list — List saved stashes
 git stash apply — Apply last stash without removing it
 git stash apply stash@{0} — Apply specific stash
 git stash pop — Apply last stash and remove from list
 git stash clear — Remove all stashes
Removing Config

 git config --global --unset user.name — Remove global user name


 git config --global --unset user.email — Remove global email

Misc

 Cron syntax basics: minute, hour, date, month, week

If you want, I can format this into a neat PDF or markdown file for you. Would that help?

You might also like