...
This document examples are based on Douglas Hubler's repository on git-hub: http://github.com/dhubler/sipxecs
Working with GIT repository
...
in local mode
A developer should be aware of three things in order to locally work with GIT repositories:
...
Code Block |
---|
git fetch origin //make sure that you are in sync with the remote repository (origin) git checkout master-4.2 //move to master-4.2 branch, because we want to base our work on this git rebase origin/master-4.2 //rebase your master-4.2 branch with the origin master-4.2 branch just to keep in sync with the latest source code git checkout TEST //move to your branch git rebase master-4.2 //keep in sync your branch with your master-4.2 branch that now is in sync with origin's master-4.2 |
If rebase cannot be performed automatically, git may require you to manually perform some changes.
...
Code Block |
---|
Falling back to patching base and 3-way merge...
Auto-merging sipXconfig/neoconf/src/org/sipfoundry/sipxconfig/bulk/csv/Index.java
CONFLICT (content): Merge conflict in sipXconfig/neoconf/src/org/sipfoundry/sipxconfig/bulk/csv/Index.java
Auto-merging sipXconfig/neoconf/src/org/sipfoundry/sipxconfig/common/AbstractUser.java
Auto-merging sipXconfig/neoconf/test/org/sipfoundry/sipxconfig/bulk/ldap/UserMapperTest.java
CONFLICT (add/add): Merge conflict in sipXconfig/neoconf/test/org/sipfoundry/sipxconfig/bulk/ldap/UserMapperTest.java
Auto-merging sipXconfig/web/src/org/sipfoundry/sipxconfig/site/admin/ldap/LdapServer.java
Failed to merge in the changes.Patch failed at 0001 XX-6279: Import contact information from LDAP
When you have resolved this problem run "git rebase --continue".If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".
[mirceac@decebal sipxecs]$ git add sipXconfig/neoconf/src/org/sipfoundry/sipxconfig/bulk/csv/Index.java
[mirceac@decebal sipxecs]$ git add sipXconfig/neoconf/test/org/sipfoundry/sipxconfig/bulk/ldap/UserMapperTest.java
[mirceac@decebal sipxecs]$ git rebase --continue
|
Code Block |
---|
git format-patch master-4.2 -o <output directory>
|
Code Block |
---|
[mirceac@decebal sipxecs]$ git format-patch master-4.2 -o /home/mirceac/patches/
/home/mirceac/patches/0001-UC-TEST-Patch-title.patch
[mirceac@decebal sipxecs]$
|
Code Block |
---|
git checkout sipXconfig/neoconf/etc/freeswitch/freeswitch.xml
|
Working with GIT repository in remote mode
The work in remote mode introduces a new term: upstream
Basically we will have:
- upstream repository is git-hub Douglas's repository
- origin your git-hub repository after forking
- local is your local copy of your origin repository
Essentially, there are not big differences but you have to be aware that you are working now with three repositories. What is nice working in remote mode is that all your work will be stored on git-hub, you can create your own branches to keep any experimental/prototyping work you may want and in the same time to share it with everyone on git-hub
In order to set-up such environment follow below steps
- Create an account on git-hub and add open-source repository (free)
- From git-hub project page, fork Douglas's project into your own repository
- Create ssh keys on both sides: local and on your git account(to prepare your local clone):
- Clone your project in read/write mode
Sample: git clone git@github.com:mirceac/
sipxecs.git
In git terms, your remote repository is called: origin and Douglas's is called: upstream
At this point you have tracked only your repository (origin)
run: git remote (or git remote -v)
return: origin
5. Verify your branches created locally:
git branch
it may return only master. master-4.2 branch may be hidden. In order to show this branch too run:
git branch -a
In order to switch to hidden branch run: git checkout -b master-4.2 origin/master-4.2
run once again:
git branch
and you will see both master and master-4.2 branches
5. Track upstream remote repository (Douglas's):
git remote add upstream git://github.com/dhubler/sipxecs.git (note the read-only url, there is no chance to write on upstream)
Run again git remote
return: origin
upstream
6. Get upstream
git fetch upstream
7. In order to keep in sync the upstream repository (Douglas's) and origin repository (yours) run:
git fetch upstream
git merge upstream/master
8. Assuming you have done some development on your clone on branch master and you want to push changes in your repo on git-hub:
Move to the branch you want to push on git-hub (master or master-4.2)
Assuming that you developed on branch topic, merge topic branch with the current one (the one you moved on):
git merge topic
Perform push on git-hub:
git push origin master (git push origin master-4.2 if you have your changes in master-4.2 branch)
9. If you cannot perform a merge operation you can cancel it by running:
git reset --hard
10. Send your changes to Douglas: From your project's page, click the "pull request" button
Some documentation links:
http://help.github.com/forking/
http://stackoverflow.com/questions/67699/how-do-i-clone-all-remote-branches-with-git
http://www.question-defense.com/2009/02/04/add-a-ssh-key-to-your-github-account-for-a-linux-server
http://www.kernel.org/pub/software/scm/git/docs/git-merge.html