Practical Web Programming
Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

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.

Tuesday, March 25, 2014

Git: Merge Develop Branch to Master

Normally when developing, you would make your changes in develop branch and when releasing, merge develop to master branch. Here's the best way to do it:

$ git checkout master                 # make sure you are in master branch
$ git fetch                                  # download commit from remote branch
$ git reset --hard origin/master     # removes changes/commits in local master branch (if any)
$ git merge origin/develop           # merge remote develop to master (the current branch)
$ git push origin master              # push the changes to remote repo

Git: Delete All Local Branches That Were Already Merged to Master

In Git, to clean up your local repository of already merged branches to master (aka pruning), run this command:

$  git checkout master
$  git branch --merged master | grep -v "\* master" | xargs -n 1 git branch -d

This is three commands in one, made possible via pipes ("|").

1) git branch --merged master     # list all the branches that have been merged to master
2) grep -v "\* master"                 # select all the branches that does not match "* master"
3) xargs -n 1 git branch -d          # execute git branch -d with 1 parameter - the branches that was returned by #2

Thursday, December 19, 2013

git: Merge master to feature_branch Often to Minimize Conflicts

One of the best way to avoid conflicts (or large unmanageable conflicts) is to merge master often to develop or whatever feature branch you are working on. This way, you will integrate all the changes made to master (by other developers or you) to the current branch as you progress. Here's an easy way to do it:

$ git checkout feature_branch
$ git pull origin master

The first command makes sure you are on the right branch, and the second one fetches the changes in origin/master repo and merge into the current branch. Take note that if you omit origin master from the second command, it will try to fetch and merge origin/feature_branch - not what you want to do here.

Wednesday, March 20, 2013

How to Clone a Remote Git Repository

To clone a remote git repository, run the following command in the terminal/console. 


$ git clone https://github.com/kabalweg/MyTestProject.git


This will create a directory named MyTestProject in the current path, initializes a .git directory inside it, pulls down all the data of that repository, and checks out a working copy of the latest version. If you go into the new git directory, you'll see the project files in there, ready to be worked on.   

If you want change the name of the directory to be created, use the command below.   


$ git clone https://github.com/kabalweg/MyTestProject.git YourTestProject 


Where YourTestProject is the name of the directory you want when git clones the repository.

This example uses github as the remote repository, but you can use this format with any repo provider like beanstalk.

Recent Post