(Trigger Warning: I'm only slightly less of a noob than y'all so be nice and pls tell me if something here is incorrect.)
There is already an intro to git / version control on the 125 website. Read this first for a refresher on the importance of version control. This guide will be about using git to collaborate on MP7. There are also much more complete guides such as the Atlassian Git Tutorial or Git's own tutorial. These tutorials cover about everything you need to know about git but may be a bit cumbersome for newcomers. This guide will be about quickly setting up a repository for you and your partner to easily collaborate on MP7.
You wont be able to collaborate without a shared git repository. First, have one partner create a new repository on GitHub. Give it an apropriate name and description. Make sure it is public and don't add any initial files.
A new repo on GitHub is useless if you and you partner can't access it on your own machines. Have one partner navigate to directory of your project. (Probably something like /path/to/AndroidStudioProjects/my_cool_mp7_project/
) If you haven't yet created you project do so now.
Next open the terminal in this directory. On linux you probably have an option to right click
-> open terminal here
. On windows, right click
-> git bash here
. On mac you will have to open the terminal the usual way then cd
into your projects directory. (Unless you have enabled the option)
Now you can initialize the repository with git init
. If you run git status
you will see a bunch of red "untracked files". These files need to be staged so you can commit them. (More on that here) You can add all files with git add .
or add files individually with git add /path/to/my_file.ext
. If you run git status
again you will see that your files have been staged and are now colored green.
Now that your files are staged you can commit them with git commit
this will pull up your default editor, which is probably vim or nano. If it's vim you might have some issues. The editor is opened so you can write a commit message. If you want to avoid the struggles of closing vim, you can also specify a commit message in the command itself git commit -m "my commit message"
.
Lastly you have to add the remote repository you made on GitHub and push your changes. This can be done with git remote add origin https://github.com/myusername/my_repo_name.git
and git push -u origin master
.
Congratulations! You have created your first git repository on GitHub!
Here are the steps more succinctly:
cd /path/to/AndroidStudioProjects/my_cool_mp7_project/
git init
git add .
git commit -m "my commit message"
git remote add origin https://github.com/myusername/my_repo_name.git
git push -u origin master
In order for you guys to collaborate you first need to add your partner as a collaborator. This will give them commit access in your repo (only you have commit access by default). You can find collaborators in the settings tab of your repository's GitHub page.
Seach for your partner's GitHub username. Make sure you chose the correct one.
When you add them as a collaborator they will be sent an email. Once they accept, they will have to clone your repo.
From the point of view of the partner who did not create the repo the command is:
git clone https://github.com/mypartnersusername/their_repo_name.git
(For both partners)
Every time you make a significant change you can stage the changes with git add my_changed_file.ext
(to add my_changed_file.ext) or git add .
to add all files. Changes are committed with git commit
(to write the commit message in the editor) or git commit -m "my commit message"
(you probably want to use this one). Push to GitHub with git push origin master
(Always after you commit though).
Again, after you make changes:
git add .
git commit -m "my commit message"
git push origin master
To retrieve changes that your partner has made:
git pull --no-edit
Remember, the default terminal on mac and linux should work for git but on windows you will have to run all commands from the git bash
terminal, not the command prompt.
To be done once after creating your repository:
cd /path/to/AndroidStudioProjects/my_cool_mp7_project/
git init
git add .
git commit -m "my commit message"
git remote add origin https://github.com/myusername/my_repo_name.git
git push -u origin master
To be done once by the partner who did not create the repository:
git clone https://github.com/mypartnersusername/their_repo_name.git
To be done every time you want to commit and push changes:
git add .
git commit -m "my commit message"
git push origin master
To be done every time you want to pull your partners changes:
git pull --no-edit