Git mastery: Your local repo is also a remote repo!

Say what??

Here is an interesting tidbit about your local Git repo. You can push to it and pull/fetch from it. Anything you can do with a remote repo, you can do it with your local repo.

How do I do this?

Just specify . where you would normally specify a remote repo.

git push origin [local src]:[dest] would push your local branch at local src to the remote origin branch dest.

git push . [local src]:[local dest] would "push" your local branch at local src to the local branch local dest

Of course, you can replace local src with a commit hash as well...

Why does this matter?

I'm glad you asked. This is actually an incredible resource; for the simple fact that you can push, pull, and fetch branches that you are not currently on. In essence, this allows you to manipulate other branches without checking them out.

If you are like me, and need to update tons of branches while you have uncommitted code (Why though? Because reasons!), being able to do so without changing your current HEAD is a lifesaver. Just imagine you are pushing code to update remote branches, and again, replace the remote name with . and you're good to go!

Who in their right mind would even...?

Actually, if you use Git a lot and become interested in maintaining a good record of the history of code you have written (the lines in your git tree), you'll eventually want to be able to manipulate branches with precision.

If you're juggling changes that aren't checked in or committed, you could use a shit ton of git stash commands - which I have done on many occasions. But that gets pretty messy and you have to mentally keep track of what's going on and where all of your code is. If you can master this paradigm of "local repo as a remote repo", you won't have to dick around with the stash when you want to manipulate other branches. Save stashing for testing code in other branches ;)