-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Collaborating on Projects with Git
This is a guide focused on collaborating on Android projects together with teammates using Git.
First, you need to properly setup git for your project:
git init
Next, setup a .gitignore file at the root with the contents from this file to ignore files that shouldn't be shared between collaborators.
If you have already committed files and need to remove them after adding the ignore, you can run this command to remove them before committing.
git rm -r --cached .
You can now add the initial files to git using the SourceTree / Github client or by typing:
git add .
git commit -am "Initial commit"
Next, make sure you have setup a repository on github and then add that repo as the origin:
git remote add origin git@github.com:myusername/reponame.git
and now go ahead and push the code to Github with:
git push origin master
You can also use your favorite Git GUI (for example the Github client) to do a lot of this process as well.
The following outlines how to collaborate with others using git. When first starting a session working on a project, we need to pull any updates pushed by other collaborators:
git checkout master
git pull origin master
New features should be added in special feature branches that allow changes to be made in isolation. First, we can create a new branch to work on:
git checkout -b my_branch_name
Now changes can be locally committed to the branch:
git add .
git commit -am "Initial commit"
You can check your current branch:
git branch
and push changes back to github in a branch with:
git push -u origin new_branch_name
While working on the branch, be sure to rebase with master to pull in mainline changes:
git checkout master
git pull origin master
git checkout your_branch
git rebase master
If there are conflicts, they have to be resolved in the files and then you need to run:
git rebase --continue
until all conflicts have been resolved.
When a branch is ready to be merged, a pull request should be opened. Make sure your branch is up to data with master with the rebasing steps above. Then push branch to github with git push -u origin new_branch_name
.
Go the repository on github and look for:
Press "Create Pull Request" and then if there's an associated issue then in the description part of the PR list the issue number you are closing like this: closes #23
to automatically close the related issue when this is merged.
Tag your team members so they can review your pull request. When you get approval from your team members then merge the pull request back into the mainline.
Often when collaborating on a project with others, you need to have maps work across multiple computers. The problem is that the map key fingerprint is different from computer to computer and thus by default maps will only work on the computer that was used to generate the key.
The simplest fix is described in detail within this stackoverflow post but in short you can get the debug.keystore
from one of the team members, check that into git and then instruct other team members to replace their debug.keystore
file with the one from repository. See also this link and this guide.
When working with different teammates that may have different Android Build Tools or SDK versions installed, you might might find it convenient to use Jake Wharton's SDK Manager plugin to download these packages automatically. Follow these installation instructions for more info.
Created by CodePath with much help from the community. Contributed content licensed under cc-wiki with attribution required. You are free to remix and reuse, as long as you attribute and use a similar license.
Finding these guides helpful?
We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.
Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.