Android Studio and GIT: local file:// method. Creating a repo, push and pull on Windows.

Needing to work in a collaborative android project would require some version control and project sharing. Most of the time this happens within a local network at the office. Git offers various methods to do this, being using github the most common one, but if you feel like you don’t want to share your work with the wold, or you don’t want to be paying for a private membership, or simply the online thing is not the right approach, or you like instant pulling and pushing, or you don’t want a headache messing with SSH and windows services, you could do this within your already working network, skipping the need of any service setup or online service registration.

  1. On the windows “server” machine, start a new android project using Android Studio (AS).
  2. Share the folder of the created project.
  3. Activate version control on your server machine created project by selecting on the menu VCS > Enable Version Control Integration
  4. On the dialog select Git
  5. Right click on the root folder inside the “Project” tree view pane and select Git > Add
  6. Right click again and select Git > Commit directory
  7. Enter a commit message.. something like “New Project” and by hovering the Commit button, select “Commit and Push”. (if you just select Commit then you neet to then push by going to VCS > Git > Push
  8. AS will ask you to define a remote:
    1. Name: Origin
    2. URL: file:////<your ip or network name>/<shared folder>/.git
  9. Create a new branch on server by clicking on Git: Master at the lower right corner of AS and selecting origin/master>Checkout as new local branch. Name this something like “server-branch”.
  10. Now for the Clients. If your client is a Mac, connect to the shared folder.
  11. Open AS and choose Check out project from Version Control >Git
  12. For the URL enter one of the options below.
    1. For windows: file:////<your ip or network name>/<shared folder>/.git
    2. For Mac: /Volumes/<shared folder>/.git
  13. Fill in the directory and the folder name and click clone. After this youll get a dialog asking to open… DO NOT OPEN IT!.. CLICK NO!. If you clicked yes by mistake, AS will mess up your project. Close AS, erase the folder and repeat the step 11.
  14. Now choose Open an existing Android Studio project in AS and browse for the project created on step 12.
  15. Click on Add root if prompted about an unregistered VCS root.
  16. Click on “Git: <some name>” on the lower right corner of AS and choose Origin-Master > Check out as new branch. Set a name like client1-branch
  17. Everything should be working now.. lets test the server commits.
    1. On the server, using server-branch, make some change like adding a comment somewhere and save.
    2. Still on server, now you have to commit and then push. To do both click on the green up arrow on icon menu, enter a commit message, and use the button commit> Commit and Push…
    3. Now sync the client by clicking the down blue arrow. choose Branch Defaut and Stash. The comment should appear.
  18. Lets test out the client:
    1. On client, write another comment somewhere and save.
    2. Still on client, now you have to commit and push. User the green up arrow, enter comment and choose commit and push.
    3. On server click blue down arrow.. Branch Defaut and Stash. The client change should appear.
  19. Final test, conflict resolving:
    1. enter a comment on client on some file and then and another on server, on the same file.
    2. On any machine, commit and push the change.
    3. On the other machine, commit and push the change.
    4. You’ll get a Push rejected message because of the conflict, click on the Merge button.
    5. On the the next dialog you can merge both files by clicking merge, and then inserting into the middle code pane, codes from left (local) and right (remote).
    6. You’ll probably get again the message of push rejected. You cant commit and push by using the green up arrow since nothing has changed but …
  20. If no changes has being made since the last commit, and you need to push again, youll need to go to  VCS > Git > Push… (this skips commiting to the repo).


Leave a Reply

Your email address will not be published.