Some git work commands. Keep in mind if you have any question what things are doing you can run
man git
for the manual page of git
and for example man git-commit
for the manual page of git commit
command.
If you like to add something to the last commit then you can run:
git add <your changes files>
then you can add it with the following command to the last commit:
git commit --amend --no-edit
The --amend
means that we append the last commit.
The --no-edit
means that we don't want edit the commit message again.
- Use
git stash
to store the changes you want to add. - Use
git rebase -i HEAD~10
(or however many commits back you want to see). - Mark the commit for edit by changing the word
pick
at the start of the line intoedit
. Don't delete the other lines as that would delete the commits. - Save the rebase file, and git will drop back to the shell and wait for you to fix that commit.
- Pop the stash by using git stash pop
- Add your file with
git add <file>
. - Amend the commit with
git commit --amend --no-edit
. - Do a
git rebase --continue
which will rewrite the rest of your commits against the new one. - Repeat from step 2 onwards if you have marked more than one commit for edit.
git branch --merged| egrep -v "(^\*|staging)" | xargs git branch -d
git branch --merged
-> lists all merged bracnhesegrep -v "(^\*|staging)"
-> ignore staging branch, more can be added via pipexargs git branch -d
-> remove every branch in the list