Practical Web Programming

Friday, June 05, 2015

Compare Between Branches in Github

Before you deploy or when you make a release note, typically you would compare master with develop branch to get the differences and find out what has changed. In Github, it's so easy to do that. All you have to do it is go to the following link and supply the branches that you want to compare[OUTDATED_BRANCH]...[UPDATED_BRANCH]


git: Delete All Local Branches that Already Merged to Master

After sometime using git and creating branches for every feature or bug, you will end up with a lot of branches. Some has been merged to the master branch and some are not. For those that been merged to master, there is no point for them to be in your local machine, so it's better to delete those so it will not clatter your local repository. To do that you just run the command below in your local repo:

git branch --merged | grep -vE "\*|\develop|\master" | xargs -n 1 git branch -d

This command will delete all local branches that are merged to master except for the current checked out branch, develop and master.

Wednesday, April 15, 2015

Easily Prepare master Branch for Deployment

1) Create a bash script named "prepare_for_deployment" in the root folder of your project and put the git command below:

    release_date=$(date +'%Y-%m-%d')
    git checkout master
    git fetch
    git reset --hard origin/master
    git merge origin/develop
    git push origin master
    git tag $release_date -m "$release_date"
    git push --tags origin $release_date
2) Make the file executable
    $ chmod u+x prepare_for_deployment
3) To run the script:

    $ ./prepare_for_deployment

NOTE: You can add the path to the script in your $PATH so you don't have to type "./" before the name.

Recent Post