This cheatsheet lists commands we use to submit a PR (pull request) to a GH (github) repo. It is mainly for my reference, but if you found it helpful, leave a like!
git init - turns the current folder into a local Git repository. It creates a hidden .git directory and enables Git tracking and version history locally.
git checkout -b *branch_name* - Creates and switches to the new branch
git checkout - switch to the previous branch
git branch *branch_name* - Creates new branch
git switch -c *branch_name* - Creates and switches to the new branch
git switch *branch_name* - switches to the specified branch
git branch -d *branch_name* - deletes specified branch
git status to check files that have been changed
git diff shows the code difference in the terminal
git add . to stage all files for commit
git restore --staged . to unstage all files or
git restore --staged *filename* to unstage specific file
git commit -m "*commit message goes here*" to commit the changes
You can use git commit and then you’ll be redirected to either nano or vi editors to enter the commit message.
For nano editor: Type message, ^X to exit the file and y to save the file.
For vi editor: i for insert mode, type the message and then ESC. :wq to save text and exit, or :q to simply exit
git push --set-upstream origin *branch_name* to push the branch and changes. git push works too, but you have to mention the branch_name the first time you push changes.
Revert commits before they are pushed to GH repo:
-
Soft Reset – Changes stay, commit is reverted
-
git log(Shows commit log. We find the previous commit hash with it.) git reset --soft ***previous commit hash***git reset —soft HEAD^1
-
-
Hard Reset – Changes and commit both are reverted
git reset --hard ***previous commit hash***git reset —hard HEAD^1
Revert commits after they are pushed to the GH repo:
git revert ***commit hash*** to revert the commit that was pushed. This will revert the commit locally. This should be followed by git push so that the changes are reverted on GH repo.
git bisect checks what broke between specific commits and narrows down the search between a commit range.
Reset the local branch to match the remote branch:
-
git fetch originfetches the latest changes from the remote branch -
git reset --hard origin/*branch_name*resets local branch -
git clean -f -dto delete untracked files -
git pullto pull all the contents from the repo
git log --oneline --graph --decorate -5 - shows recent Git history as a compact branch graph.
-
git log→ shows the commit history. -
--oneline→ displays each commit on a single, short line instead of showing the full commit details. -
--graph→ draws an ASCII graph showing how branches and merges relate to each other. -
--decorate→ shows labels such asHEAD,main, and branch names next to commits. -
-5→ shows only the 5 most recent commits.
Top comments (0)