Important
Replace filename with period (.) to include all files.
Examples are wrapped in blockquotes.
You can add multiple commands in one line by seprating them with semi-colon (;)
View All Files (Including Hidden)
ls -a
ls _foldername_
ls .git
git status
Note
Unstaged Files are Red.
Staged Files are Green.
git add _filename_
git restore --staged _filename_
git commit -m "_yourmessage_"
git log
Note
Press q to exit it.
git restore (filename)
Note
Each commit has a commit ID which can be found in Commit History.
Resetting will unstage all subsequent commits; do a git stash
prior to save them.
To reset local repository to a particular point with reference of a commit
git reset _commit-id_
When you neither want to commit the changes nor lose the them:
git stash
All staged and unstages changes will be saved to stash. You can bring them back to their respective place by:
git stash pop
Delete Stash:
git stash clear
Just like how we assign names to phone numbers in contact list, same way we set origin for identifying repository.
git remote add origin _repository-url_
git push origin _branchname_
When changes between local repo & remote repo aren't synced:
git push origin branchname -f
git remote -v
git rm --cached -r .
git branch _branchname_
git checkout _branchname_
Note
head -> points towards which branch is currently selected
git fetch --all
git pull origin _branchname_
git fetch --all
git checkout origin/master -- _filePath_
Note
"origin/master" is subject to change depending on where you're working.
git branch -d _branch_
git push origin --delete _branch_
git checkout _branch-you-wanna-merge-in_
git merge _branch-to-merge_
git clone _forked-repository-url_
git remote add upstream _repository-url_
git branch _branchname_
git checkout _branchname_
Note
Origin will be set by default and will refer to the forked version of original repository & Upstream will refer to the original repository.
You can't push to uptream directly so you'll have to make a Pull Request
- Automatic
git pull upstream _branchname_
- Manually
git fetch --all --prune git checkout _branch-you-wish-to-sync_ git reset --hard upstream/main
Note
--prune includes deleted files as well.
git config --global user.email "you@example.com"
git config --global user.name "Your Name
git shortlog -s -n