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 git@github.com:username/Backchannel.git
Sets the origin for the local Backchannel repo. git@github.com: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 git@github.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.
git fetch
- Check the status of your local repo, gives which files have changed, which are untracked, etc
git status
- To find out which is the current branch
git 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