| Backup local changes, they are branch independent |
| git stash push -m "Test XXX" | Comment for the stored changes |
| git stash push -u -m "Test XXX" | Comment for the stored changes include untracked files too 👍 |
| git stash push -a -m "Test XXX" | Comment for the stored changes include all files even .gitignored |
| git stash list | List stored changed |
| git stash show 1 | Show content of previous stored changes |
| git stash apply 0 | Apply last stored changes |
| git stash pop 0 | Apply stash and remove if from stash. (restore from trashbin) |
| git stash drop 1 | Remove stash without apply ⚠️ (clean trashbin) |
| Work on Branches |
| git add FileName | Add new or changed file for commit |
| git remove FileName | Remove file from git for commit |
| git diff | Show changes for next commit |
| git commit -m "Commit Text | Commit changes (localy) |
| git push | Send commited changes to server |
| git switch branchName | Switch to another branch ❗ Use stash/commit first to remove store and remove current changes |
| git switch -c newBranch baseBranch | Switch to new created branch based on another branch. Ex: git switch -c feature-0815 develop |
| git branch | List local branches |
| git branch -r | List remote branches |
| git branch -a | List all branches |
| git branch -d deleteBranchName | Delete branch |
| Undo an commit |
| git reflog | List of commits |
| git revert commitId | Undo changes of the selected commit (refLogId / commitId) |
| git reset commitId | Undo changes of the selected commit and all following⚠️ commits (refLogId / commitId) |
| git reset --hard origin/branchName | Reset local changes and make local state identiacal to remote state of branch |
| git cherry-pick -n commitId | Apply comit from an different branch (-n := no auto commit) |
| Remove accidently added file from last commit |
| git rm FileName | Remove the file from the repository |
| git commit --amend --no-edit | Amend the last commit to exclude this file |
| git push --force-with-lease origin branchName | Force push to overwrite remote history (IF ALREADY PUSHED) |
| Change accidently added file from last commit |
| git add .gitignore | Add change file for commit |
| git commit --amend --no-edit | Amend the last commit to exclude this file |
| git push --force-with-lease origin branchName | Force push to overwrite remote history (IF ALREADY PUSHED) |
| Work with branches |
| git init -b master | Create new local repository for brnach master. Run only once. |
| git checkout -b newBranch | Create new local branch |
| git push -u origin newBranch | Send data to server |
| git merge --no-ff branchName | Merge changes to branch |
| git checkout master | Fetch updates from master to local branch |
| git merge --into-name master | merge current branch into branch master |
| Work with remote servers |
| git remote set-url origin https://Username@Domainname/Path.git | Set once remove server |
| git remote add origin https://Username@Domainname/Path.git | Set once remove server |
| git push -u origin master | Push local version to remove brnach master |
| git clone https://Username@Domainname/Path.git | Localen clone von remote anlegen |
| Global git commands |
| git config --global core.autocrlf true | Automatic convert CR+LF to/from LF only |
| git config --global user.name "Firstname Lastname" | Set your name for commits |
| git config --global user.email your@sample.og | Set your email for commits |
| git config --global http.sslbackend schannel | Select ssl backend |
| git config set --global init.defaultBranch main | Define default branch name |
| git config --global http.sslVerify false | ⚡ Disabled certificate check should not be used |
| git config --global -l | List global config |
| GIT-Setup |
| git config core.excludesfile .gitignore.local | Define local ignore setup. |
| git update-index --assume-unchanged YOUR_FILE_OR_DIRECTORY | Ignore local file/dir |