Sunday's lesson in git and other fun (not) stuff
Sunday funday... not. It all started with wanting to get git set up for a project I've been working on for some time. I've been the only developer and just never got around to setting it up with version control (gasp... I know. don't judge me. lol). Well, now we have others joining the team so I figured it was about time. I learned a lot of stuff, gleaned bits and pieces and now we are off to the races. We have the repo, can push/pull/ have users, groups, permissions. And it all works.
And, as if life was not already exciting enough, just to make it all a bit more intersesting, right after I set up git I accidently deleted the entire website! But have no fear, Constant Readers, with the fancy footwork of stash and restore we were [mostly] back - all except for those pesky ignore files. Blessedly I had a copy of those too... whew! I didn't make it to church today, but I sure did a lot of praying!! lol
Here are some of my steps - and missteps. Perhaps they may help someone else. Keep in mind that I am not an expert sysadmin. I have a Drupal bud named Erald who can do this in his sleep with one arm tied behind his back. What took me hours to figure out, he would have done in minutes. But, we all start at zero at least once, am I right? These are methods that worked for me. Please research and double check before using. I've given links to referencing information where possible. Also MAKE BACKUPS!!
Creating the repo
The first thing I did was to create a new account as this was for a client. They have several websites, so in order to manage them all together I decided to create an organization rather than a personal account. https://help.github.com/articles/creating-a-new-organization-account
From within the organization I clicked on the "plus-sign" at the top to create a new repository. Ours are private so I shelled out a few bucks during the sign up and I was on my way. Note, I did not create with an initial readme file and found that I was then presented with all the steps I was going to need to take on my server:
echo # thewebsite >> README.md
git add README.md
git commit -m "first commit"
git remote add origin firstname.lastname@example.org:kappaluppa/thewebsite.git*
git push -u origin master
(Looking back this seems all so easy. But I did run into a few snafus along the way.)
* you can click on the icon next to the clone url and it will copy the info you will need to add for the remote. This is basically 'copy to the clipboard and is used all over the place.
I already had a site up on the server and needed to add it to the repo. So after these few steps I continued on with
git add .
git commit -m "adding all my existing files to the repo"
git push origin master
One of the problems I ran into was a file size limit with github. https://help.github.com/articles/working-with-large-files I deleted the file in question before trying to remove it via git. I was having no luck removing the file name from the cache information. Since I was just starting out, I deleted the .git folder I had created and started over with git init - step one above.
So now I have my repo, I have my server files and I've added my files from the server to the repo. Drupal comes with a basic gitignore file that sets up your repo to ignore files you don't want to overwrite or be overwitten, such as the settings.php. You can add more or leave as is.
Git has a lot more settings that you may want to consider, but this barebones info should at least get you going. Git is also good about letting you know along the way about some settings you should take care of, such as --global https://help.github.com/articles/setting-your-username-in-git and other stuff. http://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
Users & Groups
So, this server only had 1 user set up - root. We didn't want everyone playing around in there, so I had to add some new users. When I did it I added the users and ran into permissions problems then created a group and so on. But doing it again I'd create the group first or just add the users to the group that owned the files. Remember I deleted all the files? Well, when they were restored they all had the group and ownership if root:root and could not be seen via the internet. So the first thing I did was change the ownership of the files and directories. Check the owner ship and other info of the files by using:
ls -lah (list all files in a human readable format) http://www.computerhope.com/unix/uls.htm
I went to /home/thewebsite/public_html where the webroot was and used chown (change file owner) to change it http://linux.die.net/man/1/chown
chown -R thewebsite:thewebsite *
meaning that everything in that directory and directories in that directory and all files would be owned by and in the group of "thewebsite." I needed to do this so that users would not have to sudo every time they wanted to change something and so that they could push/pull to the repo. Now I needed to add users and add them to the group. So at the command line I did the following to get Sarah B added and part of the group: http://www.howtogeek.com/50787/add-a-user-to-a-group-or-second-group-on-...
useradd SarahB (added Sarah B as a user)
passwd SarahB (to set a password for Sarah B)
You will be asked for a password and to repeat it
Since I was using the group thewebsite, I added Sarah B to the group that already existed. If I wanted to add a new group I'd do groupadd <groupname>
usermod -a -G thewebsite SarahB (add to the group called thewebsite the user SarahB)
You can check the info about SarahB by using:
id SarahB (you will get the user id, group id of groups that user belongs to)
Still not done! We've got our files, our repo, our users, our groups - all ready to go. But without permissions, they can't do anything. Kind of like how a vampire cannot enter your home unless invited. http://buffy.wikia.com/wiki/Vampire We need to chmod (change file modes) the directories and add the right permissions. There are a lot of references out there, but this one was very helpful http://www.comentum.com/unix-osx-permissions.html
chmod -R g+rw .git/ ((chmod)change file mode (-R)recursively through the directories and give the (g)group owning the file (+rw)read, write and execute permissions.)
I had to do this in the directory containing the .git folder.
So by now the new users that were created can push/pull to their github accounts and edit files. Yay! There are a lot more options in each one of these steps available to you. Use them as best suit your needs. If you find that any of these steps are glaringly dangerous to the safety of the server, please let me know so I can update this cheatsheet. Best of luck. I'd like to hear if this has helped you out or if you have some important info that should be added.
Now, after all that... time to start working. ugh.