Monday, October 17, 2011

Experiences with Git and Github

To check your current branch

git branch

Adding a new branch name

git branch branch_name


To do a fetch and merge at one go:-

Do a git pull


Committing code with others comitting at the same time:

Scenario 1: others have also modified the same file that you have modified..

git fetch

Caution:

Now before doing a git merge origin/branch_name --> (Keeping in mind you are modifiying a file in the same branch)

Take a backup of your file(s) into another folder/location; wherever there is a conflict

Do a git checkout path(for the file name say app/views/folder_name/file_name)

then do the git merge origin/branch_name

Committing your code on git:-

To commit your code on git you need to use:-

git commit -a -m "Appropriate Message wrt the commit"

here, the -a command mostly implies for all.

To commit only certain files:-

To commit multiple files at one time you need to separate each file with a whitespace.

git commit -m "Appropriate Message" filename(s)

One can also push all code using:-

git push origin branch_name


You can't push your commits when:

When others have made a commit and you haven't updated your code upto the latest commit; it would give an error saying non fast forward updates are not allowed.

To do a (fetch + merge for a specific branch):


Do a git pull origin branch_name

To switch to another branch

git checkout branch_name

No comments:

Post a Comment