git – add local files to a git repository in local file system (bare git repo).
In this blow, I will show you how you can turn your local files into a github style repository. In my case I had files in `/etc/puppet` that I wanted to version control, but I wanted to push to a bare repository in the same machine or localhost. Here are the steps I followed –
Files to version control : /etc/puppet
Bare git repository that we will push changes in /etc/puppet : /var/lib/puppet/gitrepo/
1. Create a github style git repository in /var/lib/puppet/gitrepo
1 2 3 | root@linubuvmb:/ # mkdir -p /var/lib/puppet/gitrepo && cd /var/lib/puppet/gitrepo root@linubuvmb: /var/lib/puppet/gitrepo # git --bare init Initialized empty Git repository in /var/lib/puppet/gitrepo/ |
2. Initialize files as git repository
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | root@linubuvmb:/ # cd /etc/puppet root@linubuvmb: /etc/puppet # git init Initialized empty Git repository in /etc/puppet/ .git/ root@linubuvmb: /etc/puppet # git add . root@linubuvmb: /etc/puppet # git commit -m 'First commit' [master (root-commit) b71ef42] First commit 50 files changed, 3913 insertions(+) create mode 100644 auth.conf create mode 100644 environments /example_env/README .environment create mode 100755 etckeeper-commit-post create mode 100755 etckeeper-commit-pre create mode 100644 fileserver.conf create mode 100644 manifests /base .pp create mode 100644 manifests /nodes .pp create mode 100644 manifests /site .pp create mode 100644 modules /apache/manifests/init .pp ... |
3. Add bare repo as remote
1 | root@linubuvmb: /etc/puppet # git remote add origin file:///var/lib/puppet/gitrepo/ |
4. Push to local git repository
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | root@linubuvmb: /etc/puppet # git push -u origin master Counting objects: 84, done . Delta compression using up to 2 threads. Compressing objects: 100% (70 /70 ), done . Writing objects: 100% (84 /84 ), 129.33 KiB | 0 bytes /s , done . Total 84 (delta 6), reused 0 (delta 0) To file : ///var/lib/puppet/gitrepo/ * [new branch] master -> master Branch master set up to track remote branch master from origin. root@linubuvmb: /etc/puppet # git status On branch master Your branch is up-to- date with 'origin/master' . Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: puppet.conf no changes added to commit (use "git add" and /or "git commit -a" ) root@linubuvmb: /etc/puppet # git commit -a [master f57997d] test 1 file changed, 1 deletion(-) root@linubuvmb: /etc/puppet # git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working directory clean |
Reference –