GIT: Switching from code branch to dev/master

We recently upgraded to a latest version of Django (1.8). Earlier, we were running Django 1.2 and we created a new GIT branch called django18 that had all the migration changes. After going Live, we planned to stay on the django18 branch for a while so that if anything goes catastrophic, we can revert back to dev/master. But it had been a few months now and we didn’t revert back to dev and master. After I merged the django18 branch with dev, and then merged dev to master – here’s what I did to switch our dev and production server to run dev and master branches respectively. It wasn’t as easy as doing a checkout dev/master and just pulling code. With a lot of code and structural changes, I had to run through a lot of hoops to get this done right:

# Make sure the Django1.8 branch is up to date
git checkout task/django18
git status

# update dev branch
git checkout dev
git pull varun.verma dev

# update master branch
git checkout master
git pull varun.verma master

'''
error: The following untracked working tree files would be overwritten by merge:
	portal/__init__.pyc
	portal/api/__init__.pyc
	portal/api/admin.pyc
	portal/api/management/__init__.pyc
	portal/api/migrations/0001_initial.pyc
	portal/api/migrations/__init__.pyc
	portal/api/models.pyc
	portal/api/urls.pyc
	...
Aborting
'''

# View the the untracked files that will be cleaned. Review that all are .pyc files
git clean -fx --dry-run

# Now remove the untracked files
git clean -fx

# pull master branch again and it will complain about the statuc files as shown below
git pull varun.verma master

'''
From gitserver.domain.com:/var/git/your_repo
 * branch            master     -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
	portal/static/admin/css/base.css
	portal/static/admin/css/changelists.css
	portal/static/admin/css/dashboard.css
	portal/static/admin/css/forms.css
	portal/static/admin/css/ie.css
	...
Please move or remove them before you can merge.
Aborting
'''

# View the untracked directories
git clean -dfx --dry-run
'''
Would remove portal/bi/management/
Would remove portal/another_app/management/
Would remove portal/static/admin/
'''

# Now get rid of the portal/static directory and build it again later
git clean -dfx

# pull master branch again and it will pull this time and list the additions/deletions/modifications
git pull varun.verma master

# make sure master local and origin are in sync
git status

'''
On branch master
Your branch is up-to-date with 'origin/master'.
'''

# now pull the static files
python manage.py collectstatic --settings= portal.settings_stage

# modify wsgi.py file to use the stage settings file
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "portal.settings_stage")

# restart apache
apache2ctl restart

# You may notice a list of .pyc files that now show as modified. You will have to checkout each of them individually
git checkout portal/__init__.pyc
...

Advertisements
Posted in GIT

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s