Git Commands
Cheatsheet
Command | Description |
---|---|
git init | Initializes a new Git repository |
git clone <repository> | Clones a repository into a new directory |
git add <file> | Adds file changes to the staging area |
git commit -m "message" | Records changes to the repository with a commit message |
git status | Displays the status of changes |
git diff | Shows changes between commits, commit and working tree, etc. |
git branch | Lists all local branches or creates a new branch |
git checkout <branch> | Switches to a different branch |
git merge <branch> | Merges changes from a specified branch into the current branch |
git pull | Fetches and merges changes from a remote repository |
git push | Pushes local changes to a remote repository |
git remote remove origin | Removes remote origin |
git remote add <name> <url> | Adds a remote repository |
git remote remove <name> | Removes a remote repository |
git log | Displays commit history |
git reset <file> | Resets the file's changes in the staging area |
git revert <commit> | Reverts a specific commit |
git stash | Temporarily saves changes that are not ready to be committed |
git tag <tag_name> | Adds a tag to a specific commit |
git fetch --prune | Fetches changes and removes references to deleted branches |
WATCH VIDEO HERE:
Roll back to previous commit or push
1 ) Get all actions you've done
Git log —oneline
2) Figure out which one you want to go back to
Git checkout (the number)
Git reset (the number) removes everything else after it
To Note! : Resetting doesn’t delete extra files
Git reset —hard (the number) https://stackoverflow.com/questions/9529078/how-do-i-use-git-reset-hard-head-to-revert-to-a-previous-commit
To force dev
branch to become main
branch (protected branch)
this could be due to the fact that there are many merge conflicts between dev and main branch.
- Create backup branch for main (main-backup)
- Kill the main branch
- Create new branch main using dev
- git switch main
- unprotect main on gitlab/github
- force push as main
git push origin main -f