How to start using Git on an existing Drupal project
https://www.zyxware.com/sites/default/files/styles/user_image/public/default_images/index.png?itok=2YmREnrP
BY smruthy.rajendran
8 years ago
Drupal-Technical
0 comments comment

Git is one of the most versatile opensource version control systems out there. If you have not already started using Git for your Drupal Development projects, this article should help you get started with it.

Please note: I have been using Linux as my development environment, and almost all my illustrations would be for Linux. Still, the commands for using git should be the same for git implementations on all OSes. Please add in a comment if you have any doubts.

Steps

  1. Download all the files of the existing site.
  2. Run the command git init, from the webroot directory. This command creates an empty git repository or re-initializes an existing git repository. When this command is executed, a hidden directory named ".git" is created inside the webroot.
  3. Add a .gitignore file inside the webroot. (This file contains the name of files and directories which the user does not want to track via git).
  4. Add all the files in the webroot to git. This is done using git add command. It adds all files in the directory. If you want to add each file one by one, you can specify the file path instead of the dot(.) symbol.
    If any files or directories are specified in the .gitignore file, they will be ignored. If you try to add a file that is added to the .gitignore file, you will get the following message:
    The following paths are ignored by one of your .gitignore files: 
    ...list of file paths...
    Use -f if you really want to add them. 
    fatal: no files added 
    
  5. Once all the files are added to git, the details should be logged into the repository. This is done using the command git commit. You can add a message to describe about the changes made in the current commit

Example

Here I demonstrate how I normally add an existing project into git:

I've a Drupal 7 installation in my system, which I wish to add to a git repo. It is in a folder named 'drupal7' and placed inside /var/www/. So my webroot is /var/www/drupal7.

From the terminal, I move to the webroot of my project 'drupal7'.

smruthy@inspiron:~$ cd /var/www/drupal7/

I'm going to list all the files in my webroot using 'ls' command

smruthy@inspiron:/var/www/drupal7$ ls -a

.              .gitignore         install.php         modules     sites
..             .htaccess          INSTALL.sqlite.txt  nbproject   themes
authorize.php  includes           INSTALL.txt         profiles    update.php
CHANGELOG.txt  index.php          LICENSE.txt         README.txt  UPGRADE.txt
COPYRIGHT.txt  INSTALL.mysql.txt  MAINTAINERS.txt     robots.txt  web.config
cron.php       INSTALL.pgsql.txt  misc                scripts     xmlrpc.php

There is a .gitignore file inside the drupal7 webroot. The content of that file is as follows:

# Ignore configuration files that may contain sensitive information.
sites/*/settings*.php

# Ignore paths that contain user-generated content.
sites/*/files
sites/*/private

We add files or directories which we would like to be ignored by the git repo to this list.

Now we initialize git in this fodler using git init command. I also run the ls command to list the contents of .git directory that was created when the git init command was executed. I've also executed the git status command. It shows the branch I'm currently working on and the list of untracked files in the directory.

smruthy@inspiron:/var/www/drupal7$ git init
Initialized empty Git repository in /var/www/drupal7/.git/
smruthy@inspiron:/var/www/drupal7$ ls -a .git
.  ..  branches  config  description  HEAD  hooks  info  objects  refs
smruthy@inspiron:/var/www/drupal7$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#	.gitignore
#	.htaccess
#	CHANGELOG.txt
#	COPYRIGHT.txt
#	INSTALL.mysql.txt
#	INSTALL.pgsql.txt
#	INSTALL.sqlite.txt
#	INSTALL.txt
#	LICENSE.txt
#	MAINTAINERS.txt
#	README.txt
#	UPGRADE.txt
#	authorize.php
#	cron.php
#	includes/
#	index.php
#	install.php
#	misc/
#	modules/
#	nbproject/
#	profiles/
#	robots.txt
#	scripts/
#	sites/
#	themes/
#	update.php
#	web.config
#	xmlrpc.php
nothing added to commit but untracked files present (use "git add" to track)

I want to ignore .htaccess file from git repo. So I add that file into the list in the .gitignore file. If I again execute 'git status' command, .htaccess file will not be listed below the untracked files.
Now I've to add all the files under the webroot to git. For that I use the command 'git add .'. The files/directories listed in the .gitignore file will be ignored. If you execute 'git status' command now, you can see that all the files/directories which where listed under 'untracked files' will now be under 'Changes to be committed:'.
Now you have to register all the additions and changes to git repo using 'git commit' command.

smruthy@inspiron:/var/www/drupal7$ git commit -m "Initial commit"

Now all the files will be added to git repo. I'm going to execute a few more commands, for checking.

smruthy@inspiron:/var/www/drupal7$ git status
# On branch master
nothing to commit (working directory clean)
smruthy@inspiron:/var/www/drupal7$ git log
commit 217d74d5cf4af00e2d634893a844b5848aa5b27c
Author: smruthy 
Date:   Mon Jul 2 12:50:28 2012 +0530

    Initial commit
smruthy@inspiron:/var/www/drupal7$ git branch
* master
smruthy@inspiron:/var/www/drupal7$

'git status' shows the branch you are currently working on. Since there are no changes done after the last commit or any untracked file, it is showing the message 'nothing to commit (working directory clean)'

'git log' displays the details of the commits we have done to the git repo; with commit id, commit message, date and author who did the commit.

'git branch'. lists all the the branches in the repo. Now we have only one branch 'master'. If there are more branches, they will all be listed and the current working branch will be marked with *.

References:


RELATED ARTICLE

/themes/custom/zyxpro_light/images/placeholder.png
close

on 01st January 2008 / by webmaster
We have added a few new modules to our site recently. Drupal Technical StumbleThis Leave a reply Your email address will not be published. Required fields are marked * Sean (not verified) access_time 01 Dec 2020 - 02:00 Hi there, I uploaded the files, enabled the modules to use SU, and now I see the link, but there is no icon... How can I fix this? Thanks, Sean webmaster access_time 01 Dec 2020 - 02:00 In reply to Icon doesn't show by Sean (not verified) What do you see when you view the source? Search for stumblethis_button and you should be able to see the code for the image and the URL. Then you should be able to troubleshoot from there. Juicy Couture Addict (not verified) access_time 01 Dec 2020 - 02:00 thanks for the post. would love to hear more of you. by the way, drupal's really popular nowadays as it has easy and fast features. you agree with me? thanks. Pagination Current page 1 Page 2 Next page Next › Last page Last » Add new comment
/themes/custom/zyxpro_light/images/placeholder.png
close

on 16th January 2008 / by webmaster
Most webmasters do not realize this, but a lot of the content on lot of websites can be accessed from multiple URLs. A simple example would be where www.example.com and example.com leads to the same page. This is a fatal mistake in Search Engine Optimization and search engines penalize you for duplicate content. The correct configuration would be where the above two urls will lead you to the same page but example.com will redirect you to www.example.com with a 301 (Moved permanently) status which will not result in search engines penalizing the page. It is very easy to configure 301 redirects using Apache .htaccess file and the process is the same for a Drupal installation also. Drupal Technical Apache htaccess SEO Leave a reply Your email address will not be published. Required fields are marked * Anonymous (not verified) access_time 01 Dec 2020 - 02:00 Hello. I'm trying to make example.com show as www.example.com, and I'm running into difficulties. I'm on Apache 2.0 and using the following lines in my httpd.conf file: RewriteEngine on RewriteCond %{HTTP_HOST} ^xxxxxxxxxx\.com$ [NC] RewriteRule ^(.*)$ http://www.xxxxxxxxxx.com/$1 [L,R=301] When I go to http://xxxxxxxxxx.com, I get http://www.xxxxxxxxxx.com (as expected). However, when I go to http://xxxxxxxxxx.com/node/1 (it's a Drupal site), I get a 404 thrown and the URL changes to xxxxxxxxxx.com/var/www/drupal/node/1. Same thing with www.xxxxxxxxxx.com/node/1. Any suggestions? I want to run without Drupal's .htaccess file (instead incorporating these calls into my httpd.conf file). webmaster access_time 01 Dec 2020 - 02:00 In reply to Rewrite including filesystem path by Anonymous (not verified) I think the problem is with the base path which results in the redirection to /var/www/ part. The best approach I would think is to start with drupal htaccess and then strip out parts and move to httpd SNVC (not verified) access_time 01 Dec 2020 - 02:00 This is definitely a good guide. Thanks for this. wellyson access_time 01 Dec 2020 - 02:00 This is really nice and helpful. Pagination Current page 1 Page 2 Next page Next › Last page Last » Add new comment
/themes/custom/zyxpro_light/images/placeholder.png
close

on 08th February 2008 / by webmaster
Attachment Size slashdotit.tar.gz 173.55 KB Similar to the StumbleThis module that we had created earlier we have created another bookmarking Drupal Technical Slashdotit Leave a reply Your email address will not be published. Required fields are marked * Shlomi Fish (not verified) access_time 01 Dec 2020 - 02:00 Hi! I'm interested in this module, but Drupal 6.2 complains that it's incompatible with it. Can you please update it or tell me how? Regards, Shlomi Fish shlomifish.org webmaster access_time 01 Dec 2020 - 02:00 In reply to Can you update it for Drupal-6.x? by Shlomi Fish (not verified) Sure we are working on this currently and will post an update soon. Also we will post this module on www.drupal.org as well Cheers Anoop John Team Zyxware Anonymous (not verified) access_time 01 Dec 2020 - 02:00 Hello! Nice Article very interesting, thanks Pagination Current page 1 Page 2 Next page Next › Last page Last » Add new comment
Leave a reply
Your email address will not be published. Required fields are marked *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.