Hi everyone this are the git commands which I use frequently as a developer in my day to day life.so I thought to share this with all of you.please do comment your frequently use git commands in comment section
The git stash command is a utility that allows a developer to temporarily save modified files. However, it is a utility that should only be used occasionally because it only involves local repository history. Code stored in a local stash is not visible to other developers, nor is it replicated to other git repositories like GitHub or GitLab when a push occurs.
git stash push
- Creates a new stash and rolls back the state of all modified files
git stash apply
- Takes the files in a stash and places them back into the development workspace, but does not delete the stash from history
git stash pop
- Takes the files in a stash, places them back into the development workspace and deletes the stash from history
git checkout -b new-branch-name
1.For renaming a branch you have to checkout to that branch you have to rename
git branch -m new-branch-name
2.Delete the old
branch name by running
git push origin --delete old-branch-name
3.Reset the upstream branch to the name of your new local branch by running
git push origin -u new-branch-name.
For deleting a branch you have to checkout to another branch because git will not let you delete the branch you are currently working on
- deleting branch locally
git branch -d <branch-name>
- deleting a branch Remotely
git push origin --delete <branch-name>
git restore --staged filename
To remove the last commit from git, you can simply run
git reset --hard HEAD^
If you are removing multiple commits from the top, you can run
git reset --hard HEAD~2
to remove the last two commits. You can increase the number to remove even more commits.
To undo that specific commit, you have to use the commit hash of that specific commit
git revert cc3bbf7 --no-edit
The command above will undo the changes by creating a new commit and reverting that file to its previous state, as if it never changed.
Lastly, use git push to push the change to the remote branch.
Thank you for reading this article