Skip to content

Instantly share code, notes, and snippets.

@daniel-fanjul-alcuten
Last active December 20, 2015 17:59
Show Gist options
  • Save daniel-fanjul-alcuten/6172908 to your computer and use it in GitHub Desktop.
Save daniel-fanjul-alcuten/6172908 to your computer and use it in GitHub Desktop.
to run automatically before I login
#!/bin/bash
cd ~
hostname=$(hostname -f)
if ! [ -d .git ]; then
git init
git remote add origin [email protected]:dfanjul/dotfiles.git
else
git remote set-url origin [email protected]:dfanjul/dotfiles.git
fi
branch=$hostname
branch_ref=refs/heads/$branch
tracking_branch_ref=refs/remotes/origin/$branch
tracking_master_ref=refs/remotes/origin/master
branch_ref_in_remote=refs/heads/$branch
if ! git show-ref -q --verify $branch_ref; then
git fetch -v origin
if ! git show-ref -q --verify $tracking_branch_ref; then
git push origin $tracking_master_ref:$branch_ref_in_remote
fi
git checkout -f -b $branch -t $tracking_branch_ref
fi
git pull --ff-only
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment