git config --global user.name USERNAME
git config --global user.email EMAIL
git config --global --list
git config --global -e
cat ~/.gitconfig
git help COMMAND_NAME
git COMMAND_NAME --help
In Windows Add P4Merge installation directory as path to environment variables
git config --global merge.tool p4merge
git config --global mergetool.p4merge.path "C:/Program Files/Perforce/p4merge.exe"
git config --global mergetool.prompt false
git config --global diff.tool p4merge
git config --global difftool.p4merge.path "C:/Program Files/Perforce/p4merge.exe"
git config --global difftool.prompt false
There are 3 Local states:
- Working Directory
Contains all files and folders for the application which may or may not be managed by Git. Either way, Git is aware of those files. - Staging Area
Used to prepare for the next commit. Files are moved from modified working directory state to the staging area. - Repository (.git folder)
Contains all the commited or saved changes to the Git repo. Anything here is part of Git's history.
Consider this 4th state:
- Remote
It's another repo with its own 3 states internally.
git init PROJECT_NAME
git init .
git status
git add FILE_NAME
git add ./FOLDER_NAME
git add .
git add -A
git add -u
git commit
git commit -m "COMMIT MESSAGE"
git log
git log --oneline --graph --decorate --all
git show
git show COMMIT_ID
git show TAG_NAME
git commit -am "COMMIT MESSAGE"
git restore .
git restore FILE_NAME/FOLDER_NAME
git restore --staged .
git restore --staged FILE_NAME/FOLDER_NAME
git config --global alias.hist "log --oneline --graph --decorate --all"
git mv ORIGINALFILE_NAME CHANGEDFILE_NAME
git rm FILE_TO_REMOVE
- Branch = Timeline of Commits
- Branch Names are Labels
- Deletion Removes Label Only
- Default Branch is master branch
3 types of Merge
- Fast Forward Merge
Simplest, like never be branched, can be disabled - Automatic Merge
non-conflicting merge detected, preserves both timelines, merge commit on destination. - Manual Merge
automatic merge not possible, conflicting merge state, changes saved in merge commit.
- Like pointers
- HEAD
- Points to last commit of current branch
- can be moved
git hist
git diff
git diff COMMIT_ID COMMIT_ID
git diff COMMIT_ID HEAD
git diff BRANCH_NAME BRANCH_NAME
git difftool
git difftool COMMIT_ID COMMIT_ID
git diff BRANCH_NAME BRANCH_NAME
git branch
git branch -a
git branch BRANCH_NAME
git checkout -b BRANCH_NAME
git checkout BRANCH_NAME
git branch -d BRANCH_NAME
git merge BRANCH_NAME
git mergetool
git tag TAG_NAME
git tag --list
git tag -d TAG_NAME
git tag -a ANNOTATED_TAG_NAME -m "TAG_MESSAGE"
git show ANNOTATED_TAG_NAME
git stash
git stash list
git stash pop
git stash apply
git stash drop
git hist
git reset COMMIT_ID --soft
git reset COMMIT_ID --mixed
git reset COMMIT_ID --hard
git reflog
git clone REPO_URL
git clone REPO_URL FOLDER_NAME
git remote -v
git push REMOTE_NAME BRANCH_NAME
git fetch
git status
git pull
git remote -v
git remote set-url REMOTE_NAME REMOTE_URL
git remote show REMOTE_NAME
git push -u REMOTE_NAME BRANCH_NAME
git status
git checkout DEFAULT_BRANCH
git pull
git merge BRANCH_NAME
git push
git branch -a
git branch -d BRANCH_NAME
git branch -a
git fetch -p
git branch -a
git fetch
git branch -a
git checkout REMOTE_BRANCH_NAME
git branch -a
git push
git status
git checkout DEFAULT_BRANCH
git pull --all
git merge BRANCH_NAME
git push
git branch -a
git branch -d BRANCH_NAME
git branch -a
git push REMOTE_NAME :BRANCH_NAME
- Some Commits on remote repo
- Some Commits on local repo
- Both diverged after fetch
- Do a rebase pull to stay ahead of remote
git fetch
git status
git pull --rebase
git hist
- Change default branch from website
- Clone a new repository locally
git branch -a