git clone <URI>
git checkout -b <new_branch_name>
git branch -a
git branch <lokaler_name> origin/<remote_name> git checkout <lokaler_name>
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
You can change your last commit message by this command:
git commit --amend
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
To clean a dirty commit history (before doing a pull request) you can do a squash.
Waring: 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.