P2P Git


Have you ever had your version control server go down just when you were ready to commit some important changes for your team? Did you feel stuck, blocked, or hopeless? This happened to me only yesterday but luckily we use Git for version control. Git is a decentralized version control system which means that you don’t actually need a central host to continue working. While lots of people already know that you can commit, merge, and branch locally without a network connection you may be surprised to know that you can also push and pull changes while the central Github repository is offline using a Peer 2 Peer connection.

Last night I wanted to push changes from my iMac in the office so I could pull them with my Macbook and work from home. Our internal Github repository went offline and I went to Google to find a little trick I’d used in the past. Setting an alias to run a local git server is as simple as:
git config --global alias.serve "daemon --verbose --export-all --base-path=.git --reuseaddr --strict-paths .git/"

This creates a git command, serve, that you can run from the command line to launch a local Git server over your current repository.

git serve

I ran this command on my iMac and got output saying something like, “Ready to rumble“. My local git server was ready to accept connections from other computers. On my Macbook I was then able to pull the commits I had just made on the iMac using it’s IP address with the git pull command:

git pull git://10.15.12.15/ feature/newWidget

The “feature/newWidget” was the name of the branch I was pulling. Some output text on the Mac confirmed a remote connection happened and the new commits magically showed up on my Macbook Pro. This same idea could apply if I needed to share my latest branch with a coworker before heading home. I could commit to a feature branch on my iMac and then say, “pull the changes from my iMac at 10.15.12.15”. My coworker could run a similar git pull and see all of the commits appear in their local repository. The alias I used above is read only, however you could also set it up so that coworkers have write access and can push directly to your local git repo as they complete work.

So the next time your internal version control host goes offline don’t sweat it! Run a local git server and share away! I haven’t tried it but I believe this might work with a git-svn setup as well.

Windows git thinks my file is dirty


Do you have dirty files in git? Are you frustrated with how git thinks you’ve soiled a file that you haven’t actually touched? Are you looking for a way to tell git to stop bugging you? Hi I’m Cliff. You’re here because you have dirty files (but you have clean underwear). I’m here because I finally managed to work around a long standing issue where git thought my files were modified under Windows. The problem originates from machines with two different operating systems working on the same project. If you commit files from a *nix system and set the executable bit on then when you clone the project or pull the commit on Windows, git will treat these files as being altered. This is because the executable bit does not exist on Windows so the file appears different on the filesystem. To prevent git from treating these changes as different you should run this command:

git config core.fileMode false

That sets the global config for git to ignore file mode changes (things like read/write/execute). You can set it globally or use it for one off commands like:

git -c core.filemode=false diff