git clone <URI>
git checkout -b <new_branch_name>
git branch -a
git branch <lokaler_name> origin/<remote_name> git checkout <lokaler_name>
# delete a local branch git branch -d <the_local_branch> # remove a remote branch (if you know what you are doing) git push origin --delete <the_remote_branch>
git clone -b <branch_name> <remote_repo_url>
git commit --allow-empty -m "empty commit to trigger CI" git push
git stash
This applies newest (last) stash
git stash apply
This applies a selected stash
git stash apply stash@{2}
git stash list
Example:
$ git stash list stash@{0}: WIP on master: 049d078 Create index file stash@{1}: WIP on master: c264051 Revert "Add file_size" stash@{2}: WIP on master: 21d80a5 Add number to log
git reflog
git reset
This should be executed in repo root:
git checkout .
Yet another way to revert all uncommitted changes (longer to type, but works from any subdirectory):
git reset --hard HEAD
git reset --hard 'xxxxx' git clean -f -d git push -f
You can change your last commit message by this command:
git commit --amend
git remote -v
Zunächst muss das Original Repository hinzugefügt werden:
# Zunächst muss das Original Repository hinzugefügt werden: git remote add upstream <original_repository> # Dann fetchen: git fetch upstream # In den lokalen branch wechseln der akualisiert werden soll (z. B. master): git checkout master # und dann mergen: git merge upstream/master git push # If there were any new commits, rebase your development branch git checkout <dev_branch> git rebase upstream/master
To clean a dirty commit history (before doing a pull request) you can do a squash.
Warning: Do not rebase commits that exist outside of your repository. At least do not rebase branches where others are working on.
Lets say you want to fix up the last 5 commits you do this:
git rebase -i HEAD~5
Then you get an editor window where you have to do the changes. Here you can rename the top commit by writing “r” (for reword) and change the commit text. If you want to discard all other commits you write “f” (for fixup) infront of them. Now you save the file and the GIT magic is happening.
Here is an overview of all options: - p, pick = use commit - r, reword = use commit, but edit the commit message - e, edit = use commit, but stop for amending - s, squash = use commit, but meld into previous commit - f, fixup = like “squash”, but discard this commit’s log message - x, exec = run command (the rest of the line) using shell - d, drop = remove commit
If something bad happens after saving where you have to fix up something first, you can continue the rebase with:
git rebase --continue
When everyhing is ok you have to do a forced push:
git push -f
If you have already done a pull request (on GitHub) this squash still works afterwards. The “dirty” commit history of the PR will also be changed.
git config --global credential.helper store
Set username for every repository (global)
git config --global user.name "<username>"
Set username for single repository (local)
git config user.name "<username>"
Create global ignore settings that are used everywhere: - create ~/.gitignore_global
file with ignore settings - execute git config --global core.excludesfile ~/.gitignore_global
- also see: https://jayeshkawli.ghost.io/using-global-gitignore-on-mac/