-
Notifications
You must be signed in to change notification settings - Fork 12
Getting Started: Git
Depending on what operating system you run and what development environments you use, you may already have Git installed. We will focus on the command line interface of Git in this tutorial (once you understand how to use it, you may use whatever GUI client you like), so open a terminal or command prompt and type git
. If you get something other than a file not found error, you should be good to go.
If you do not already have Git installed, follow the instructions for you operating system on the Git Website.
Once Git is intalled, you should make sure that it works (e.g., that you have it in your path, etc.). If you get any response from typing git
in a terminal or command prompt, everything should be fine.
Setting up a repository is easy, you just type git init
in the directory that should host your repository. You can then add files with git add <filename>
and these files will be tracked. During the lecture, we created a repository for an Android project as follows:
android create project --target 1 --name HelloAndroid --path /path/to/repo/HelloAndroid \
--activity MainActivity --package com.example.helloandroid
cd /path/to/repo/HelloAndroid
git init
git add -A
Note that I assume a unix-like environment (e.g., Linux or Mac). You need to change a few things to get the above to work on Windows (such as replacing /
with \
).
You can now git commit
the files. Everytime you edit one of the tracked files, it will be marked as modified. You can check which files are modified with git status
. If you want to add a file to the staging area (i.e., include it in the next commit), you git add <filename>
the file. If you simply want to commit all changed files, you can issue git commit -a
.
The respository you created is local and not connected to any "remote" source, such as GitHub. To connect it to GitHub, you issue git remote add <name> <url>
as follows. (You should obviously replace the url with your own repository).
git remote add origin https://github.com/morganericsson/AndroidExamples.git
You can now pull and push commits from and to the remote source, e.g.
git push -u origin master
where origin
is the name of your remote source and master
is the name of your branch (just use master if you do not know what else to put there)
For more information about how to set up remote repositories at GitHub refer to the documentation. For information about how to set up private remote sources or use other services such as BitBucket, refer to their documentation.
- Git web site
- Pro Git (freely available book on Git)