Using git and github for projects
Git is a source code management tool.More on git here. github.com is a web application that allows anyone to create an account and host a public git repository. When you work in teams, we encourage you to set up a repository on github for your project.
Some basic steps:
- Create an account on github
- Install git- Depending on your OS, this will vary. For ubuntu
$ sudo apt-get install git-core git-gui git-doc
- github uses SSH keys to set up secure connection between your local repo and the public repo. Go to github help at Github help and follow the steps to set up ssh keys
- Creating a repository - Lets say we want to create a repository for Backchannel project.
- Create a repository on github
Follow steps at create a gihub repo This needs to be done only once. i.e. Even if you are working in a team, it is sufficient for only one person to create the repo on github.
- Create local repository
Create a directory where the repository will be stored
$ mkdir ~/backchannel
Init a git repo in that directory
$ cd ~/backchannel $ git init
You will get an output like An empty git repository has been initialized on the terminal. This initializes a git repo locally.
- Connect local and github repos
$ git remote add origin email@example.com:username/Backchannel.git
Sets the origin for the local Backchannel repo. firstname.lastname@example.org:username/Backchannel.git is public url of your github repo. You will find this when on your github repo page.
- Adding files to git
Any new files you create need to explicitly added to git. It tells git to track the changes in these files.
git add hello_world.rb
- Committing the changes to git- This commits all your changes to local repo. These changes have not yet been pushed to the remote repo on github
git commit -m "first commit"
- Push changes to remote repo
git push origin master
- Clone a repository - Now if your teammate has already created the repo, you just need to clone it.
$ git clone email@example.com:teammates_username/Backchannel.git
- Fetching changes - Now your local repo and the remote repo on github may get out of sync as other team members commit their code. You need to fetch their changes to your local repository.
- Check the status of your local repo, gives which files have changed, which are untracked, etc
- To find out which is the current branch
So typical workflow once you create a repo is:
git fetch git add foo.rb git status git commit -m "commit msg" git push