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.

The first way I'll show you to move a change to the Live server will be the "safe" way. I'm calling the safe way because you can avoid code conflicts in real time by merging multiple edits in a single file instead of trying to overwrite one with the other.

Fetching changes with "git fetch"

  • Switch to the "Remote - Live" terminal tab
  • Type "git fetch" to query the central repo for any changes not present on the live server.
  • (Enter your password, if needed)

When I pressed Enter, git compared my repo with the central repo, and since there was a difference, it downloaded the information about the difference.

Now that they have the same information, if I type "git fetch" again, we won't see anything output to the screen because there's nothing new to show.

If we type "git status", we'll see the message:

# On branch master
# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
#
nothing to commit (working directory clean)

This shows us that our branch (on the live server) is behind 'origin/master' (the central repo) by 1 commit and that it can be fast-forwarded. The "and can be fast-forwarded" part always makes me happy when I see it because it means I can merge the changes without having to worry about fixing merge conflicts.

If you work alone and always make your changes locally and push to live (never making a change directly on the live server) this should always be the case, and will make your work much easier.

If you work on a team, or need to make a quick fix directly on your server for some reason, and forget to push it to the central repo, and pull it to your local repo before you do anymore work, you may run into an issue where your merge can not be fast-forwarded. We'll take a look at what to do in that scenario later.

Comparing our Repo with the Central Remote Repo with "git diff"

If you'd like to see the actual changes in the files that will be merged, you can use the "git diff " command.

  • I'll type "git diff origin/master" and press Enter to compare my repo with the master branch of the "origin" repo (which is the central remote in almost all cases.)

When I do that we'll see a lot of red lines that have a "-" next to them indicating they've been deleted. This may seem confusing when you're first getting used to the "diff" command because we never had the files, so we definitely didn't delete them. The reason the information is displayed this way is because Git considers your local repo to be the end result. So, to get from the current state of the remote to current state of your local copy, the files would have to be deleted.

I find the "git diff" command most useful, when I've made minor changes, and/or want to inspect the actual text differences. When I've installed entire modules, or made large changes at once, the "git log" command can actually come in very handy to compare repositories.

  • I'll press the "q" key to quit the diff view

Comparing our Repo with the Central Remote Repo with "git log --oneline origin/master"

In an earlier video we briefly looked at how to use the "git log" command, so I won't go over that again, but I will show you how it can be used to get a high level overview of the difference between your repositories.

  • I'll type "git log --oneline" to see to see the commits that are on my current machine.
  • Then I'll type "git log --oneline origin/master" to see the commits that are on my central remote repository.

As you can see there is one additional commit on the central remote repository that is not on my live server, and it was when I installed ctools 1.5. Viewing the git log in this way can help you understand what you are going to merge into your current repository in a way that "git diff" can't portray as well.

Each method of comparisons can be more useful depending on the amount of code that has changed since the last merge, and what you want to know.

Merging the Central Repo into the Live Repo with "git merge"

Now that we know what the change is that we would like to merge, and that it can be fast forwarded, the process is quite simple to merge the change into our live environment. The command we'll use is "git merge ". This will merge the branch specified by into our current branch.

  • I'll type "git merge origin/master" and press Enter

When I do that, you'll see the list of all the files that are created by the merge and if I scroll up to the top of the merge you'll see the message:

Updating ec05ced..5acc135
Fast-forward

So, the merge was updated and fast-forwarded to match the state of the remote repository.

If I type "git log --oneline", you'll see that the latest commit is the one where we installed ctools 1.5. Finally, if we go to our live site, and refresh the modules page, we'll see the "Chaos Tools Suite" section is now available.