
You can find many nice git cheat sheets everywhere on the web, but let's just quote GitHub's git cheat sheet which provides you with most useful git commands. That is not my intent, I won't enumerate all basic commands everybody knows and uses everyday, but list some commands that I use less often and that I want to remind myself of, often because I can never remember their exact syntax.
I tried to organize git commands by situation where you can need them and I added the link to the official documentation.
git cherry-pick ebe6952^..905e379ebe6952 to commit 905e379git push ebe6952:main where ebe6952 is the latest commit you want to push
ebe6952A -> B -> C -> D -> E on your local repository and you only want to push C and Dgit refloggit add . //(to stage modifications to integrate to commit)
git commit --amend
git commit --amend will open your git editor to allow you to change the commit messagegit checkout dev
git pull
git checkout featurebranch
git rebase dev
git push --force
As a colleague suggested me, if you don't need your local main branch to be up-to-date, you can win a few keystrokes and some time by replacing the above commands by the following commands:
git fetch origin
git rebase origin/dev
git push --force
It does the same thing than the previous set of commands, but just does not merge the changes of dev on your local dev branch. And as most of the time you don't need to and want to stay on your feature branch, that's easier and quicker to do it this way.
git rebase -i HEAD~3
git stash save "myFriendlyStashName" will save your local changes in a stash with the name "myFriendlyStashName"git stash list, you can easily find its number:
git stash pop "stash@{0}" or apply it with git stash apply "stash@{0}"git push --force on the repository and you want to reset your local repositorygit fetch
git reset origin/master --hard
--softgit reset HEAD^ filenamegit reset --soft HEAD~1git branch -f myBranch ebe6952git update-git-for-windows
git config --add remote.origin.fetch +refs/pull/*/merge:refs/remotes/origin/pr/*
git checkout pr/196
git config command once and each fetch will also fetch the PRInstead of adding a space to a file just to have something to commit to trigger a pipeline you are testing, just do :
git commit --allow-empty -m "improve ci"
git update-index --chmod=+x script.sh
src,build, docs ... folders like suggested in this .NET project structure.src folder while keeping the files history.git mv command but you have to first remove or move your untracked files and folder (csproj.user, bin/, obj/) and to specify in the command not to move your src folder (using !(src)).git mv ./!(src) src/