Useful git stuff


Teresa Kubacka


July 26, 2022

Because every now and then there is this thing you need to do with git, but because you do it not so often, you have to google it for like 30 sec. 

Useful git commands


To create a new completely empty branch:

git switch --orphan <new branch>
git commit --allow-empty -m "Initial commit on orphan branch"
git push -u origin <new branch>

src Article on branches

To pull a new branch from the server without touching the current branch: git fetch <remote_name> <branch_name> which in most cases is src

git fetch origin <branch_name>

Unstaging files

added but not committed

committed but not pushed

git reset --soft HEAD^ 
git reset HEAD path/to/unwanted_file
git commit -c ORIG_HEAD 

The last command will recommit with the original commit message