software engineering

How to replace master branch in git, entirely, from another branch?

By Adam K Dean on

If you want to completely replace a branch by merging over another, the follow trick will help you, as it has helped me:

git checkout yourbranch  
git merge -s ours master  
git checkout master  
git merge yourbranch  

Remove .DS_Store from git repository

By Adam K Dean on

The following will help you remove .DS_Store from your git repository.

$ find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
$ echo ".DS_Store" >> .gitignore
$ git add .gitignore
$ git commit -m ".DS_Store removed from repository"

Now you can relax.

Using another private key with git

By Adam K Dean on

It's quite normal to have different private keys for different git servers, but how do you provide a different identity file like you do with SSH?

The answer comes in a text file; config.

Create a text file in your ssh directory, which is usually .ssh:

$ touch ~/.ssh/config

Then open it with your favourite text editor, for me, this is currently atom:

$ atom ~/.ssh/config

Now, we can use this file to configure different hosts. The following should be pretty self explanatory. For your information, in case you're a bit confused, the identity file is your private key.

    User git
    IdentityFile /Users/adam/.ssh/yourkey
    IdentitiesOnly yes

You'll notice the host and hostname are different. This means you can have a host configured for which actually points to another hostname, such as a source control server, e.g.

boot2docker DNS not working

By Adam K Dean on

If you're using Docker on OSX, then you'll be using a VM to run your Docker service on, as it needs Linux, not Unix. The most popular of these seems to be boot2docker, though dvm also seems to be quite popular. Other solutions are available.

I have a problem where sometimes boot2docker's DNS just doesn't seem to work.

I found some instructions on how to fix it though:

$ boot2docker ssh
$ sudo udhcpc
udhcpc (v1.22.1) started
Sending discover...
Sending select for
Lease of obtained, lease time 86400
deleting routers
route: SIOCDELRT: No such process
adding dns    
$ sudo /etc/init.d/docker restart
$ exit

Now if you attempt to ping Google, it should work!

Remove branch from remote git repo

By Adam K Dean on

To remove a branch from a remote git repository, you have to push an empty branch.

$ git push origin :branch-name
- [deleted]        branch-name

If you want to also remove it from the local repo, delete the branch:

$ git checkout master 
Switch to branch 'master'

$ git branch -D branch-name
Deleted branch branch-name (was abcd123)

We change branch as you can't delete the branch you're on.