git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
git config --global --list
git config --get remote.origin.url
git --no-pager rev-parse --is-inside-work-tree
true = yes, False = not associated
rm -rf .git
Files that are already tracked by Git and you added in .gitignore
git rm -r --cached .Removes the files from the Git index- Now
git add .to add in stage git commit -m "removed files should not be on git"to commitgit pushnow push code.- Delete local branches only --
git fetch --prune
git reset --soft HEAD~1
Undo last commit but keep changes staged
git reset --hard HEAD~1
Undo last commit and delete all changes
git reset --mixed HEAD~1 or git reset HEAD~1 (default)
Undo last commit and move changes to unstaged
git reset HEAD hash_code (mixed)
Undo last commit and move file changes to unstageds
git push origin --force >> Branch will be reset
Ways
First make sure both branch are in sync (pull, push)
git checkout target-branch git merge source-branch
Tags mark important points in a project's history for easy reference, like version releases. Simplifies tracking and versioning.
-
List tags
- git tag
- git tag -l
-
Create a tag
- git tag tag_name
- git push origin tag_name
-
Example:
- git tag v1.0
- git push origin v1.0
Temporarily save your uncommitted changes without committing them to the repository.
This is particularly useful when you need to switch branches or perform other operations but want to keep your current work intact.
Multiple Stash (LIFO)
Git Stash Commands
git stash list
git stash apply
Two ways
git remote add repo-b git fetch repo-b git merge repo-b/main --allow-unrelated-histories git commit -m "Merged repo-b into root" git push
git remote add repo-b git fetch repo-b git read-tree --prefix=repo-b-folder/ -u repo-b/main git commit -m "Merged repo-b into folder" git push