Monday, March 31, 2014

Git pull tips

My project team is using Git (Open Source software) as a version control system to handle all the changes we made in the code. This software, combined with Bitbucket, a free code-hosting service, makes a really powerful tool which makes life easier (at least the programmer's life).

When we want to pull all the changes from the remote repository, we use the general pattern for the "pull" command:

> git pull [options] [<repository> [<refspec>...]]

The "standard" way to pull the remote repository is by typing:
> git pull

This fetches and integrates the remote repository with your local repository or local branch. However, a stashing operation before pulling is strongly recommended in order to avoid merge conflicts with not-done work (code tasks in progress). Git documentation defines the stashing operation as the one that "takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time." Then, we should type:

> git stash
> git pull

After these two consecutive operations, we can easily check if there exists something to be merged by using the "status" command:

> git status
If the pulling operation was successful, the console will show a message "no things need to be merged", otherwise, it will display an "unmerged" message, and you will have to decide what changes you want to keep by editing each one of the files listed. When all the files are merged (check it by typing again "git status" command), we would have our local repository already updated. Although it is also recommended to run two more commands:

> bundle install

Bundle install all the dependencies you need (gems from your specified sources). This is interesting to avoid issues if somebody changed any code in the Gemfile from the remote repository.
Finally, other useful way to keep the consistence of our application is related to possible migrations, so do not forget to run:

> rake db:migrate

This will run any migration stored in the /db/migrate/ folder. 

In my next post, I am going to talk about how to pull an specific folder when using Git.

No comments:

Post a Comment