Important Git Commands which every developer needs in his day to day life
SHIVANSH PATEL
Posted on December 4, 2022
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
stash
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
Creating a new branch from existing branch
git checkout -b new-branch-name
Renaming a branch
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.
Deleting a branch
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>
Undo Local Staged Changes in Git
git restore --staged filename
Removing the Last Commit
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.
Removing a specific commit
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.
Renaming a commit
To change the message of the most recent commit that has not been pushed to the remote repository, commit it again using the --amend flag.
git commit --amend -m"new commit messsage"
Thank you for reading this article
Posted on December 4, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.