| Global Configuration |
git config --list |
Show git configuration info |
|
git config --global user.name "John Doe" |
Globally configure committer name |
|
git config --global user.email johndoe@example.com |
Globally configure committer email |
| Initialize Repository |
cd project_dir |
Navigate to project directory |
|
git init |
Initialize a new git repository |
|
git add . |
Add all files to staging |
| Existing Directory → Git Repo |
git init |
Initialize current directory as git repo |
|
git remote add origin https://repourl/repo.git |
Add remote repository named origin |
|
git add --all |
Stage all files and folders |
|
git commit -am "initial commit" |
Commit all tracked files |
| Clone Repository |
git clone existing_dir new_dir |
Clone local repository |
|
git clone https://giturl/repo.git |
Clone remote repo via HTTPS |
|
git clone ssh://giturl/repo.git |
Clone remote repo via SSH |
| Inspect Work |
git status |
Show working tree and staging status |
|
git log |
Show commit history |
|
git log --pretty=short |
Show short commit logs |
|
git log --pretty=oneline |
Show one-line commit logs |
|
git log file |
Show commit history for a file |
|
git log --follow <file-name> |
Track file history including renames |
|
git log --stat |
Show commit statistics |
|
git diff ${FILENAME} |
Compare file with HEAD version |
|
git blame file |
Show who modified each line |
| Cleanup / Reset |
git reset --soft origin master |
Reset commits, keep changes staged |
|
git reset --hard origin master |
Reset commits and discard changes |
|
git log -- ${FILENAME} |
Show history of deleted file |
| Branching |
git branch -a |
List all branches |
|
git fetch |
Fetch all remote branches |
|
git checkout -b newbranch |
Create and switch to new branch |
|
git checkout branch |
Switch branch |
|
git merge otherbranch |
Merge another branch into current |
|
git push origin newbranch |
Push branch to remote |
|
git branch -D oldbranch |
Delete local branch |
|
git push origin --delete oldbranch |
Delete remote branch |
| Merge Conflict |
git mergetool |
Open merge conflict resolution tool |
|
git diff --base file |
View base version during conflict |
|
git diff --theirs file |
View incoming changes |
|
git diff --ours file |
View local changes |
|
git rebase --continue |
Continue rebase after resolving conflicts |