Adrian Andreias

Jan 22, 2013

git your home dir

Having all sorts of .vimrc, /.vim (like .sls files syntax), /.gitconfig settings in my Linux home dir made want to easy port this between servers. So I initialized and pushed to server a git repository and wanted to pull files from git on another server:

cd ~
git clone ssh://<git user>@<git server>/<repo path> .
fatal: destination path '.' already exists and is not an empty directory.

So, we need to get a git repo to a non-empty directory. Stackoverflow comes in handy (as most of the time) and tells us to:

cd ~
git init
git remote add origin ssh://host/repo.git
git pull origin master
posted at 17:53 ·  · git

Jan 18, 2013

my git reminder

(to be updated)

1. Create the local git repository

Even if you don't plan to use a git server and only store files on your localhost you should create a git repository as early as possible because:

  • you will have a file editing history, provided that you'll commit frequently
  • it only takes a few seconds to create a git repo

(Note that "git commit" means something slightly different than "svn commit". Since svn always assumes having a svn server, git can be used just on your local file system, a git server is not mandatory. Git will keep track of your changes in his internal database stored in directory .git by default. git push would be the equivalent of svn commit, that is publishing changes to a server).

Without further ado:

  1. git init # this will create the git database under directory .git from current path
  2. create file .gitignore. This contains the list of files that will not be added to git database. Here's what mine usually contains: .idea *.pyc settings.py
  3. git add * # to add all files
  4. git commit -a # to commit all files

Read more in the git book.

And GIT for SVN users:

2. Initial server push

Once you have the local git repository you'll want to publish to the git server.

  1. Create the repository on your git server:

    cd /var/repos mkdir myproject.git cd myproject.git git init --bare
    
  2. Add remote server:

    sudo git remote add origin
    ssh://<git user>@<git server>/var/repos/myproject.git
    
  3. and push your local repository to remote server:

    sudo git push -u origin master
    

Inspiration:

posted at 10:44 ·  · git

Jan 14, 2013

move .git up

After initializing the git repo to /src/salt/.git I discovered I also need to define some pillars in /srv/pillar and needed to move the repo to parent directory (/srv/.git). Fortunately git is smart enough to detect this and automatically rewrite paths in its database. You just need to move the database to parent directory and add original directory:

cp -r /srv/salt ~/salt_backup # backup repo
cd /srv/salt/
mv .git ..
git add salt
git commit -a

(obviously, this was needed because I didn't want to create a new repo and lose the existing commits history)

Thanks go to http://stackoverflow.com/a/3247756.