Update cloned repo with source

If like me you have a lot a cloned git repos but need to update them  with the original repo then this post is for you. With git it is very easy to do this. From within the clone run the following git commands:

git remote add upstream <original repo url>
git fetch upstream
git pull upstream <target branch, usually master>

Advertisements

Git squash multiple commits into one

If you ever have a scenario where you have to make a lot of changes to a branch but commit regularly so you can go back during this process if something fails BUT when you are done as a whole none of those commits actually matter except the last one (historically it will be off no use to see what was changing between revisions) you can do this in git:

Note: Before you do this all your changes need to have been committed, make sure you have nothing staged.

git reset –soft <sha_of_initial_commit>
git commit -a –amend -m “commit message”