DIRECTORY cd </file/path/code> -> change directory to a project
INITIALIZING
- git init -> initialize an empty git repository
STATUS CHECK 2. git status -> list of files changed & those which needs to be staged or commit
STAGING & UNSTAGING 3. git add -> stage a changed file 4. git add . -> stage all changed files 5. git rm --cached / git restore --staged -> unstage a file
COMMIT 6. git commit -m "message" -> commit all staged files with a message 7. git commit -am "message" -> stage all the changed files and commit with a message
BRANCH 8. git branch -> lists all branches names 9. git branch -> creates a new branch 10. git branch -d -> deletes a branch 11. git checkout -> switch to a specific branch 12. git merge -> merge a branch with main/master branch
GITHUB 13. git remote -v -> list all remote repos 14. git remote add origin .git -> connect local repo with a remote repo 15. git remote set-url origin .git -> change a remote git repo
-
git stash -> store current work locally with unstaged/untracked files (only if it clash with remote repo)
-
git stash pop -> bring stashed work back to working directory
-
git pull -> get latest changes from remote repo to local repo
-
git push origin -> push committed changes to a purticular branch
-
git log -> show all logs/commits in remote repo
-
git log --oneline -> show all logs in one line
DELETING COMMIT (don't forget to store all deleting commit id)
- [ git log --oneline -> copy commit id of a commit after which all the commits should be deleted git reset -> delete all commits after the provided commit id git log --oneline -> to check if commits are deleted git push origin -f -> forcefully delete commits in remote repo ]
RESTORE COMMIT (only be done if that commit id is present)
- [ git cherry-pick -> restore all deleted commits before this commit git log --oneline -> to check if commits are restored git push origin -> push commits to remote repo ]
SYNC GITHUB FORK (only if remote repo is forked)
- [ git remote -v -> show only forked repo git remote add origin -> add main repo as upstream git remote -v -> to check if main repo is added in upstream git fetch upstream -> fetch all changes from main repo git merge upstream/ -> merge those changes to local repo git push origin -> push those changes to forked repo ]