Important Git Commands which every developer needs in his day to day life

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 comman…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by SHIVANSH PATEL

Image description

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

Renaming a branch

For renaming a branch you have to checkout to that branch you have to rename

git branch -m new-branch-name

you can use git status to see your 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.

Thank you for reading this article


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by SHIVANSH PATEL


Print Share Comment Cite Upload Translate Updates
APA

SHIVANSH PATEL | Sciencx (2022-12-04T18:40:28+00:00) Important Git Commands which every developer needs in his day to day life. Retrieved from https://www.scien.cx/2022/12/04/important-git-commands-which-every-developer-needs-in-his-day-to-day-life/

MLA
" » Important Git Commands which every developer needs in his day to day life." SHIVANSH PATEL | Sciencx - Sunday December 4, 2022, https://www.scien.cx/2022/12/04/important-git-commands-which-every-developer-needs-in-his-day-to-day-life/
HARVARD
SHIVANSH PATEL | Sciencx Sunday December 4, 2022 » Important Git Commands which every developer needs in his day to day life., viewed ,<https://www.scien.cx/2022/12/04/important-git-commands-which-every-developer-needs-in-his-day-to-day-life/>
VANCOUVER
SHIVANSH PATEL | Sciencx - » Important Git Commands which every developer needs in his day to day life. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/12/04/important-git-commands-which-every-developer-needs-in-his-day-to-day-life/
CHICAGO
" » Important Git Commands which every developer needs in his day to day life." SHIVANSH PATEL | Sciencx - Accessed . https://www.scien.cx/2022/12/04/important-git-commands-which-every-developer-needs-in-his-day-to-day-life/
IEEE
" » Important Git Commands which every developer needs in his day to day life." SHIVANSH PATEL | Sciencx [Online]. Available: https://www.scien.cx/2022/12/04/important-git-commands-which-every-developer-needs-in-his-day-to-day-life/. [Accessed: ]
rf:citation
» Important Git Commands which every developer needs in his day to day life | SHIVANSH PATEL | Sciencx | https://www.scien.cx/2022/12/04/important-git-commands-which-every-developer-needs-in-his-day-to-day-life/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.