Git Commands for Real Projects: Reset, Remove, and More

Git commands I actually use in real projects ( Part 2 ) : When we work in real projects, Git is not just git add and git push. We often mess up commits, need to sync with remote, or clean things properly. These are some Git commands I use regularly and why. Many times there is a situation where I completely mess things up and want to go back exactly like a previous commit. In that case I use: git reset --hard <commit-id> This removes both commit and code changes. I use this only when I am very sure. Sometimes a file is already tracked and pushed, but later I realize it should not be part of Git, like secrets or config files. Then I use: git rm --cached <file-name> This removes the file from Git tracking but keeps the file locally. When I create a new branch locally and want Git to know this branch exists in remote, I use: git push -u origin bugfixes This pushes the local branch and sets upstream, so next time I can just do git push. To move between branches, I use: git checkout main To delete a local branch after cleanup or merge: git branch -d dev Some basic commands I run daily before doing anything risky: git status git log --oneline --graph These commands help me understand where I am and what is happening in the repo. Once you understand these Git basics, working in real projects becomes much easier. ( image generated using chatgpt for better visualization ) Follow me for more devops and SRE content. #git #github #VCS #versioncontrol #reset #gitreset #auditing #rm #buildinpublic #learning #selfgrowth #authorization

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories