Git - vimlesh-verma16/Notes GitHub Wiki
Git Notes
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com [ur link will come here from github when you create branch]
git push -u origin master
git add .
git commit --amend --no-edit
git push --force
git rebase -i HEAD~10
Keep the top most commit as pick and change rest of them to s (squash) again editor will open give the name to final commit
git push -f
git config --global credential.helper store
git fetch --all
git reset --hard origin/master (Works sometime )
git reset --hard origin/<BRANCH_NAME>
git clean -n (To see what will be deleted)
git clean -fdx # STAY ALERT! Untracked (.gitignore) directories and files will be gone!
git log --online
git reset --hard HEAD~1 (for reverting the last 1 commit)
git branch -D vimlesh (Delete a branch)
delete all the branches except the one you are using
for /f "delims=" %i in ('git branch ^| findstr /v "vimlesh/scan') do git branch -D %i
- mkdir phantoms (creating a folder)
- rmdir phantoms (deleting a folder)
- git mv <D:repo/fullpath/file.py> <D:repo/fullpathtofolder> (Renaming and moving a file)
git revert --no-commit 8d933eebc3a6553e0f6a6eb15921dd3cb7013920
Make sure that you have checked out the feature branch from which the PR has been created. Search the file commit history:
git log "C:\GitRepos\MyProject\SomeFile.cs"
git checkout <commit id> "C:\GitRepos\MyProject\SomeFile.cs"
git commit -m "Remove the SomeFile.cs from PR"
git push -f
git reset --soft HEAD~1 : WORK — This removes the last commit but keeps your changes intact so you can fix them in your local.
git blame filename.ext : WORK — This shows who changed each line in a file — perfect for tracking bugs (or reminding your teammate that they broke something and now it’s their turn to take responsibility).
git config --global alias.cm "commit -m" : WORK — Now, instead ofgit commit -m, just type git cm. Time saver!
git config --global alias.st "status"
git checkout -- filename.ext : WORK — This reverts the file to its last committed state. No stress, no mess.
git checkout - : WORK — This takes you back to the last branch you were on — just like hitting ‘Undo’ on your branch navigation. So quick and easy.
git branch -d branch-name # Delete locally
git push origin --delete branch-name # Delete remotely : WORK — Keeps your repo clean and organized!
git log --oneline --graph --decorate --all : WORK — This shows a beautiful, easy-to-read commit history.
git commit --amend -m "New message" : WORK — This updates your last commit message without creating a new commit.
git clone --depth=1 repo-url.git : WORK — Perfect when you don’t need old commits and want a fast setup.