git checkout -b develop # creates new branch develop and does checkout of develop git merge feature/awesomeness # merges the branch "feature/awesomeness" into the current branch git branch -d feature/bullshit # deletes local branch "feature/bullshit" git push origin :feature/bullshit # deletes remote branch "feature/bullshit" from the "origin" remote
Stash
Get single file from stash…
1
git checkout stash@{0} -- _{{filename}}_
Stash all files includinng untracked files
1
git stash -u
Committing
Add specific lines of a file to the commit interactively
1 2
git add -p -- git add -p filename
Commit the staged changes
1
git commit -m "your commit message"
Bisect
Trace buggy commit with git bisect…
Manual
1 2 3 4 5 6 7 8
git bisect reset # only needed after a bisect git bisect start git bisect good <revision>
git bisect bad <revision>
# git will checkout the next revision to check git bisect (good | bad)
Automated
1 2 3 4
git bisect start git bisect good <revision> git bisect bad <revision> git bisect run/path/to/decision/script args...
Get all remote branches as local tracking branches except master and HEAD since you already got those with the clone command.
1
for branch in'git branch -a | grep remotes/origin | grep -v HEAD | grep -v master'; do git branch --track ${branch##remotes/origin/}$branch; done
Most probably you also want to fetch and pull the remote tracking branches
1 2
git fetch --all git pull --all
Recovering your local branch from a force push
This will remove all commits previously on master and all commits done by yourself which are not yet pushed.
1 2
git fetch git reset origin/master --hard
To preserve your own changes and commit them again do the following.
1 2
git fetch git reset origin/master --soft
This will move all changes to your working directory, so you can commit them again manually. You can also do an interactive rebase. In this case you have to pick the commits you want to keep.
1 2
git fetch git rebase -i origin/master
Please note if you keep one of the commits you kept behind was one of the commits removed with the force push, that commit will again be reintroduced at the remote.