Everyday git commands
The vast majority of the projects I work with use Git as their source control. I predominantly use a Git UI tool for most of my daily Git interactions. However, there are times when I need to jump to the command line to have that extra control.
My Git client of choice is still Team Explorer built into Visual Studio. I realise there are more feature rich clients available but I like the simplicity of the Visual Studio integration and enjoy that it doesn't get in my way. Fetching, Pulling, Branching, Merging are all easily achieved without needing to leave VS. For the times I need more control, I jump down to the command line.
Top tip: Install Mads Kristensen's Visual Studio extension Open Command Line to open the command line at the relevant path with the shortcut Alt+Space
Here are the basic commands I use almost daily.
Status of working changes
git status
Add files to a commit
git add .
git add [filename]
Commit changes
git commit -m "This is my commit message"
Undo the last local commit
git reset --soft HEAD~1
Stash working changes
git stash
git stash apply
git stash drop
Switch branch
git checkout [branch name]
Delete local branch
git branch -d [branch name]
Delete remote branch
git push origin --delete [branch name]
Remove local references to old branches
git remote prune origin
Remove cached files after a gitignore update
git rm -r --cached .
git add .
git commit -m "Removed cached files after updating gitignore"
Compare commits between two branches
git log master..develop