Overview

I want to store some config files, scripts or Ansible playbooks  on a central web service to have

  • some versioning
  • know where the newest truth resides

I’m not a developer and don’t do lot of collaborative coding within a spread team. So  i mainly need to add files, change files and consume them.

Up to now i know git is “very easy” but git has many different commands to achieve similar things. “pull, fetch, merge, clone” are all downloading content to a local repository or maybe they do  part of what you need. As i want to manage real brain work output (written scripts, playbooks or config files), i prefer to not accidentally loose some content.

I found answer 12 in [1] very useful.

Solution

I’m keeping together all files belonging to the same Project or Subject in one github repository.

Creating a new repository

I do have an account on https://github.com/ and logged in through the web frontend. Clicking “+” on the right upper corner gets me a new repository. I gave the repository a Name e.g. “myrepo”.

Note: I try to find names representing the project idea or the environment the content is for. “myrepo” is only good as placeholder inside this documentation.

I fill readme.md with some reasonable content and may also file a lisence.md file.

That’s all.

Editing and creating new Files – first time

To edit, change or add files to your repository you need to clone the repository to your local filesystem. Change files there , commit them and push them back to the original repository.

I define some global user information:

$ git config --global user.name "mschreie"
$ git config --global user.email mschreie@redhat.com
$ ### cerating a starting-Directory where my (cloned) repositories reside
$ mkdir projects
$ cd $_
$ git clone https://github.com/mschreie/myrepo
$ cd myrepo/

If you want to add a new file

… copy file from some other place or create a new one in this directory and add all files not added yet, e.g.

$ copy /etc/ansible/hosts.cfg .
$ git add .

If you want to edit a file

just  do so, e.g.

$ vi <file>

 In both cases

you need to commit your changes and push them to the central/original repository

$ git commit -m "some relevant comment"
$ git status -s 
$ git push origin master

Editing and creating new Files – second time

If you edited some files on the local  server before. You already have a git-directory and a local clone of the git-Repo.

You would then need to update your repo, do the changes, commit and push.

To update your local clone repository with the newest content of your github repository:

$ git pull

Consuming files

You could clone the whole repository and make use of all files, but you can also download distinct files through

wget https://github.com/mschreie/myrepo/raw/master/file

Pleas note  “raw” in the URL. If you navigate through the web front end to the file you are looking for, you will get exactly the same URL but as “blob” with more fancy layout around.

Conclusion

We now are able to have one authoritative space, where the self created files reside. You are able to add new files, change files and consume what you created. You are also able to organize the files in different repositories.

git can do much more – it’s all i need in the first place from a non-developer perspective.

 

[1] http://stackoverflow.com/questions/9577968/how-to-upload-files-on-github