# Git Commands

##### **Git Commands (common)** 

<table border="1" id="bkmrk-git-command-descript" style="border-collapse: collapse; width: 100%; height: 431.2px;"><colgroup><col style="width: 50.0494%;"></col><col style="width: 50.0494%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">**Command**  
</td><td style="height: 29.6px;">**Description**  
</td></tr><tr><td>```shell
git help
```

</td><td>Show help information about git commands  
</td></tr><tr style="height: 46.4px;"><td style="height: 46.4px;">```shell
git init
```

</td><td style="height: 46.4px;">Init new git project in current folder (folder needs to be empty)  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">```shell
git clone git@github.com:myusername/myrepositoryname.git
```

</td><td style="height: 29.6px;">Clone a git repository from github.com  
</td></tr><tr><td>```shell
git add --all
```

</td><td>Stage all files (or `git add file.txt` for adding a single file)  
</td></tr><tr><td>```shell
git commit -m "my message"
```

</td><td>Create a commit of your stages files (do not forget to stage your files/changes before that, e.g.: `git add --all`)  
</td></tr><tr><td>```shell
git pull
```

</td><td>Pull updates from remote to current branch  
</td></tr><tr><td>```shell
git push
```

</td><td>Push your commits to remote repository  
</td></tr><tr><td>```shell
git push -u origin master
```

  
</td><td>Push your commits to (new) remote repository and set local branch to track remote branch upstream (-u is equal to --set-upstream). Useful if you don't have any upstream set up yet.  
</td></tr><tr><td>```shell
git push --follow-tags
```

</td><td>Push your commits + tags  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">```shell
git status
```

</td><td style="height: 29.6px;">Show status of unstaged files, project info, branch info, ...  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">```shell
git branch
```

</td><td style="height: 29.6px;">Show all git branches (option -a for showing remotes too)  
</td></tr><tr><td>```shell
git branch mynewbranch
```

</td><td>Create a new branch  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">```shell
git checkout myotherbranch
```

</td><td style="height: 29.6px;">Switch to another git branch  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">```shell
git log
```

</td><td style="height: 29.6px;">Show latest git commits and messages (or "git show")  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">```shell
git fetch --all
```

</td><td style="height: 29.6px;">Fetch from all remote repositories  
</td></tr><tr><td>```shell
git tag -a v0.1.0
```

</td><td>Tag current as "v0.1.0" (or `git tag -am "My Release Message" v0.1.0`). You can use `git push --follow-tags` to push all your tags to the remote.  
</td></tr><tr><td>```shell
git tag --delete v0.1.0
```

</td><td>Remove Tag "v0.1.0"  
</td></tr><tr><td>```shell
git revert commitHash
```

</td><td>Revert changes of a specific commit  
</td></tr></tbody></table>

##### **Git Commands (advanced)**

<table border="1" id="bkmrk-command-description-" style="border-collapse: collapse; width: 100%; height: 532.8px;"><colgroup><col style="width: 50%;"></col><col style="width: 50%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">**Command**  
</td><td style="height: 29.6px;">**Description**  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git stash --include-untracked  
</td><td style="height: 29.6px;">Save all changes to the stash  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git stash --include-untracked -m "stashname"  
</td><td style="height: 29.6px;">Save all changes to the stash with a name  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git stash list  
</td><td style="height: 29.6px;">Show all saved stashes</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git stashpop 0  
</td><td style="height: 29.6px;">Apply the latest stash + remove it from the stash list  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git stash apply 0  
</td><td style="height: 29.6px;">Apply the latest stash  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git stash drop 0  
</td><td style="height: 29.6px;">Remove latest stash from stash list  
</td></tr><tr><td>git stash clear  
</td><td>Remove all stash items  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">  
</td><td style="height: 29.6px;">  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git blame pathtomyfile.txt  
</td><td style="height: 29.6px;">Show information who to blame for a file change  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git diff  
</td><td style="height: 29.6px;">Show changes between two commits  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git grep "text-to-search"  
</td><td style="height: 29.6px;">Search for a specific string in commits  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">  
</td><td style="height: 29.6px;">  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git format-patch -1 &lt;commitID&gt;</td><td style="height: 29.6px;">Create a patch of a specific commit  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git apply &lt;patchfile&gt;</td><td style="height: 29.6px;">Apply a patch  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">  
</td><td style="height: 29.6px;">  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git bisect start</td><td style="height: 29.6px;">Start Bugfinding / Begin using the git bisect command  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git bisect good  
</td><td style="height: 29.6px;">Identify if a commit is "good", without the bug  
</td></tr><tr style="height: 29.6px;"><td style="height: 29.6px;">git bisect bad  
</td><td style="height: 29.6px;">Identify if a commit is "bad", with the bug  
</td></tr><tr><td>git bisect reset</td><td>Return to original head  
</td></tr><tr><td>git bisect log</td><td>Displays commits you've identified as "good" or "bad"</td></tr><tr><td>git bisect visualize</td><td>View commits that have not yet been checked</td></tr><tr><td>  
</td><td>  
</td></tr><tr><td>\# Set a new remote upstream and push changes/commits  
git remote add origin git@github.com:username/repository-name.git  
git push -u origin master  
</td><td>  
1. Command - Set a remote (if you don't have any) to your local branch  
2. Command - Push changes/commits to this new remote branch (-u is equal to --set-upstream)  
</td></tr><tr><td>  
</td><td>  
</td></tr></tbody></table>