As I mentioned in the last video, there are two common ways to move the changes from the central repo to a remote repo, like the live server: "git merge" and "git pull". The "git merge" command is safer, but takes a little longer, while "git pull" is much faster, but has the potential to cause conflicts in the code.
We've already seen how to use "git merge" so in this video, we'll take a look at the "git pull" command.
In an earlier video we downloaded ctools version 1.5. Version 1.6 is the latest, so I'll update that with Drush and push the update to the live server. I'll make this change quickly to save time, but if you're jumping in the series now, watch the video Making a Change to the Local Repository and Pushing it to the Central Repo with "git push" for details on the commands I'll use.
The first thing I'll do is enable ctools. We downloaded it earlier, but we never actually enabled it. Drush is currently configured to only look for updates to enabled modules. So I'll do that and then I'll perform the update.
- I'll type "drush en ctools" (Enables the ctools module)
- I'll type "drush up ctools -y" and press Enter (Updates ctools to 1.6)
- I'll type "git status" to see what files are staged and untracked. Since there are some untracked files present, I need to add them before I perform the commit. The "git commit -am" command won't work because it would only commit modified files, not untracked ones.
- I'll type "git add sites/all/modules/contrib/ctools" to add the ctools directory and everything inside it.
- Another "git status" will show that all of the files in the "ctools" directory are staged as either new or modified files
- I'll commit the files with "git commit -m "Updated ctools to 1.6""
Now typing "git status" will show the message:
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
Push Local Changes to the Central Repo
I'll follow that recommendation and type "git push" and press Enter. When I do, you'll see the push take place in the terminal.
When that's done, "git status" will show that the branch is up-to-date and there's nothing to commit. So, we're in sync with the central repo.
Merging the Central Repo into the Live Repo with "git pull"
Now, we can pull the changes into our live repo with the "git pull" command. "git pull" is basically the same thing as doing a "git fetch" and then a "git merge", but in a single command. Let's give it a shot.
- I'll switch the the "Remote - Live" terminal tab
- Then type "git pull" and press Enter
- Then enter my password
Once the pull is complete, we can scroll up a bit where we'll see the "fetch" part of the process when it downloads the information about the repository:
remote: Counting objects: 101, done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 101 (delta 73), reused 101 (delta 73)
Receiving objects: 100% (101/101), 25.66 KiB, done.
Resolving deltas: 100% (73/73), completed with 71 local objects.
5acc135..4e24284 master -> origin/master
Followed by the "merge" part of the process where it updates and fast-forwards the repo:
Checking out files: 100% (60/60), done.
Since it was able to fast-forward, we don't see any errors.
I'll double check that the live site is up to date by refreshing the "/admin/modules" page. When I do that, we'll see that the ctools version is now 1.6, so it worked!
As you can see, the "git pull" command can be quite a bit faster than typing "git fetch" and "git merge" individually, as long as you know exactly what has changed, and especially if you're the only one working on the project, and always make changes on local, and push to live.
As I've said before, if you work in a team, or have to make changes on the live site (quick security fixes for example) you might run into a merge conflict. Let's take a look at how that might happen, and what to do about it when it does.