Skip to content

Instantly share code, notes, and snippets.

@Sunny-unik
Last active October 21, 2023 15:38
Show Gist options
  • Save Sunny-unik/e9cf6b6c9b4509eba312211b4e774f72 to your computer and use it in GitHub Desktop.
Save Sunny-unik/e9cf6b6c9b4509eba312211b4e774f72 to your computer and use it in GitHub Desktop.
Git commands basics to advance
Basic Commands:
git clone [url]
- clone repository
git log
- show recent commits and tell where head & origin are stands in present branch
git status
- check your working tree changes
git fetch --all
- update branch info on local
git checkout <branch-name>
- change branch
git branch <branch-name>
- create new branch
git add .
- staged all files (or you specify filenames seprated by white-space in place of .)
git commit -m "intial project setup by sunny"
- commit with specified message
git push origin <branch-name>
- push to specified branch
git pull origin <branch-name>
- pull from specified branch
Advanced Commands
git reset --soft <commit_id | HEAD number>
- reset with getting change in staging section of recent commit
git push origin <branch-name> --force
- push with force flag (shorthand use '-f' instead of '--force')
NOTE: further commands are used for remove files from all github history so please take backup of repo/files before running these commands
git rm -r --cached client/.env
- remove file from git repo (require to be pushed on origin)
git filter-branch --index-filter 'git rm --cached --ignore-unmatch frontend/.env' --prune-empty 884cafb35a83fc05a43bd5f0fbf4b6f5103ccfcc head
- remove file from all git history (require to be pushed on origin)
For replace unwanted text from all git histroy steps are:
1. download bfg repo cleaner then paste it in your current repository's root folder
2. create a file named replacement.txt and write text that you want to remove and also from which text and use '==>' this signs for differentiate (you can also use regex in place text)
3. install java on your system & set declare env then restart system if java is not working
4. then run "java -jar bfg-version/jar --replace-text replacement.txt -fi '*.js'"
Git Alias Presets:
1. git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --branches"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment