3. Survey Question
Which of these describe how you use Drupal?
Our program website runs on Drupal
Our statewide website runs on Open Advocate
Our statewide website runs on Drupal, but not Open Advocate
We don’t use Drupal
4. How would you describe your role on the website(s)?
I write code/custom modules for the website
I install contributed modules, install security updates on the website or edit
configuration information in Drupal’s user interface (for example, creating
content types, adding fields or changing permissions.
I’m a project manager; I sometimes have to deal with developers who work on
I’m a content manager
None of these apply to me; I just want to know a bit more about Git.
5. What We’re
What is Git and why you
should be using it
Git setup and options
Git hosting with GitHub
Where to go next
7. Why Use Git?
For our own projects
Acts as a backup
It lets us undo changes
It promotes collaboration
To take advantage of other projects
8. But I’m not a
Drupal sites have probably have at
least 2 of these:
In Drupal 8: Configuration lives in
code, not the database.
In Drupal 7, configuration lives in
the database but can (and should)
live in code via Features.
9. How Do I Work
Using a GUI
Within your development
10. Getting Git
Download from https://git-scm.com or
Install a GUI like GitHub or Sourcetree
Open Terminal and type git; you’ll be prompted to install the
Xcode command line tools OR
Same options as Windows
13. Walking through Git: Common Tasks
Git init: Create a Git repository
Git clone: to copy an existing repo with git clone
Git add: to add files to Git
Git commit: to commit those files to your local copy
Add -m and a message and describe what you did: git
commit -m ‘I did something’
14. Walking through Git: Interacting with Remote
Add a remote repository using git remote add [name] [url]
Git pull: Push your commits to the remote repository
Git push: Pull the latest changes from the remote repository
15. Keeping track of things...
Get help with git --help or git --help command
See with list of files you’ve changed with git status
View your commit history with git log (or git log
Compare changes with git diff
17. Using Branches
By default, everything is in the Master branch
Branches let you:
Keep the master branch clean of “in development” code
Makes a copy of the then-existing master branch
All work is then done in the new branch
Only commit to master when you are done
You can publish your branch to share
18. Working with branches
Get a list of branches using git branch
Create a branch using git branch [branch name]
Delete a branch using git branch -d [branch name]
Merge your branch git merge master [branch name]
Tags let you:
Mark a specific point in time
Is essentially a branch that you can not change
List all your tags with git tag
Create a new tag with git tag ‘name’ -m ‘message’
Push a tag with git push origin ‘name’
20. Reverting changes
Use git checkout -- . or git reset --hard HEAD to revert any
uncommitted file back to the current state
Use git checkout [commit] [file] to change your local
working copy to an old version. [File] is optional.
Use git revert [commit] to undo all the work in that commit
and create a new commit undoing those changes
22. What are Github and BitBucket?
Public and private repositories
Both offer additional tools:
Nice user interfaces
Webhooks and services to integrate with other systems
Integrates well with the
Free for public repositories
Private repositories start at
Integrates well with
Free for public repositories
and small teams (less
than 5 people)
Seamless integration with
other Atlassian products,
Home of many open source
Q & A markup
Learn the Law
Jonathan Pyle’s DocAssemble
41. Learn More…
Try git in the cloud: https://try.github.io/levels/1/challenges/1
Git Cheat Sheet: https://www.git-tower.com/blog/git-cheat-
Hinweis der Redaktion
We are covering 5 things today: what Git is and why it matters, git setup and options for working with git. I’ll walk through the basic Git commands, and then do a demo of GitHub and Bitbucket’s cloud Git hosting. Finally, I’ll share some resources for next steps.
So what is Git?
It’s like document management for code. There is a master repository and then everyone who accesses that has their own local repository and a complete copy of the files. If I edit something in my working copy, I commit it to my local repository and when I’m ready to share it, I publish it to the master repository. If I screw up my working copy, I can erase what I’ve done and it hasn’t affected anything else. And if we push something bad ot the master, we can undo it.
First, why should we use version control? There’s 2 reasons: one to make our own development projects better and second, to take advantage of everyone else’s stuff.
For our own projects, Git brings order to chaos. It provides us with a history of the changes we’ve made and we can roll back. It organizes those changes in a structure we don’t really have to care about unless we need to roll back and it means if we have multiple people working on things, there isn’t a lot of stepping on toes or “wait, I’m not done using that file” kind of things.
But beyond our own work, there’s a huge amount of open source projects, mostly on Github, that we can use, modify, and contribute back if we know just a little bit of git. Some examples just within our own community are qnamarkup, Connecticut’s classroom module, and the entire DLAW template are all hosted on Github.
I know there are at least a few websites in the community that don’t have a single custom module and don’t write any of your own code, so why should you still be using Git?
Because somebody is making changes to the code that runs your Drupal website. In Drupal, Git is useful in 3 places.
The obvious use case is if you write your own code via custom modules
But even if you are just using contributed modules, someone is changing that code periodically. By using git, every time you update, you can more easily revert a bad thing or if you need to apply a patch to a contributed module, you can commit those patches to git to help you remember to recommit them next time the module changes.
And finally, configuration. Everytime you change a setting in your Drupal site, it changes somewhere. In Drupal 8, it lives in code. In Drupal 7, in the database. So out of the box, you can leverage git to rollback a bad configuration change. In Drupal 7, if you use the Features module to keep your configuration in code, you can do the same thing. So if all you do is break a view, if it is in code, you can undo it to the last known good state.
To use Git, you have really 3 options: the command line, a client application like Github client or Atlassian’s SourceTree (both free) and most development IDEs, such as phpstorm, eclipse, netbeans, sublime text, include git tools or have plugins to add git tools.
It’s largely a matter of preference and while I mostly use the command line, sometimes I do things directly in phpstorm as well. As I walk through the commands, I’ll demo in both the command line and a client.
But to use git, you need to install it. I am not going to demo how to install git but this slide has the links for Mac, Windows, and Linux operating systems.
Git works largely on adds, commits, and pushes. You work in the working directory that is local on your machine. When you add your files to git, it moves it to a staging area. When you commit, it updates your local repository and creates a record of your changes. If you push your changes to a remote repository, that commit gets recorded there as well. If you pull from a remote repository, your local repository gets updated.
And now to walk through some basic steps. I’ve created a couple local folders on my desktop that I’m going to use. Let’s start with the command line demo.
git remote add origin https://github.com/gadaniels/demo-command.git
Tell Git who you are:
git config --global user.name "Gwen Daniels"
git config --global user.email firstname.lastname@example.org
So now you know the basic everyday git commands. One of the most powerful things in git is being able to have different branches. By default, everything is in the master branch. But if that’s what is on your website, you might want to test or develop in a different branch and then merge them together. Let’s walk through that.
Besides branches, there are tags. Tags are essentially snapshots of a branch at a specific point in time. We use tags a lot at ILAO to mark sprint releases. Every 2 weeks set of code changes, gets tagged with a name and then pushed up to production. We don’t actually use the master branch directly.
I can deploy a tag or roll back to a tag just like i would with branches or master
And finally, one of the biggest powers of git is in the ability to undo your changes. You can undo local work using checkout or use revert to undo committed work.
So that’s a basic overview of Git. So what are GitHub and Bitbucket?
Well, they are hosted versions of Git. They are very similar.
We’ve used GitHub for several years at ILAO but are thinking about Bitbucket because we use Jira, another Atlassian product, for our software development project management. Again, it’s a lot of personal preference.
So let’s do a quick tour of Github.
I can, from within my browser, create a new file and commit it. While this isn’t probably normal behavior, it can be useful in emergency situations.
I can create an isuse, label it, tag it to a milestone, and or assign it to someone. If I assign it to someone, it notifies them via email.
Github will automatically notify the creator of a comment when someone comments on an issue. I can just reply in my email and it will post.
Git is free, github client, source tree are both free, both github and bitbucket will let you have at least a free public repository so the best next step if you want to do more with git is to try it. Another option is this try.github.io