The What, Why and How of starting your own private Git repo.
Git is just a place for us all to keep our code/scripts/information.
- tracks our changes
- keeps all old and new versions around
- serves as a backup
- allows us to share the latest version of our tools
- A place to store code we didn't write.
- A place to store data (try to keep each file under 10 MBs).
- A working directory (don't check in: log files, compiled files, or anything temporary).
- A place where you have to put EVERYTHING you do. Share only what you want.
We all write a lot of little scripts, tools, Excel sheets, etc, that everyone depends on. It'll save time if everyone always knows where to get the latest and greatest.
Let's say Felicia wants to share all of her Doctor Who scripts.
The first thing Felicia will need to do is get her own copy of our science fiction Git repository (repo). So Felicia goes to our shared server (melange), finds a good folder, and types:
git clone /git/SciFi.git/
If Felicia was working from another machine, she would type:
git clone fday@melange:/git/SciFi.git/
Now Felicia will see a new folder pop up:
SciFi/
Felicia now has a copy of all of our group's shared scripts and tools. This is a living folder. People make changes all the time. And Felicia can get all the newest stuff by going into her SciFi/ folder and typing:
git pull
A quick warning: Felicia won't actually work in this directory. This is just where she stores her tools, not her log files or temporary data.
Okay, now Felicia wants to put her files somewhere other people can find them, so she looks in the repository and sees the general structure:
SciFi/
BoardGames/
Books/
Comics
Movies/
TV/
Well, Felicia has an Doctor Who script she wants to share, so she navigates to the right directory and copies in her script:
cd SciFi/TV/DoctorWho/
cp /path/to/felicias_awesome_script.py .
And then Felicia adds the new script to the repo:
git add felicias_awesome_script.py
Now git knows the file exists. And any time Felicia wants to make a change to her file, she types:
git commit felicias_awesome_script.py -m "SHORT message, explaining Felicia's change"
The -m
command is just a message, so Felicia can explain what she did. We try to keep this short (under 50 characters).
After a couple of hours, Felicia has added a few new files, and made changes to a couple more. She is finally ready to share her changes with the group. So she types:
git push
And now, since I also have a copy of the SciFI repo, I can see all of Felicia's changes by going to my own copy of the repo and typing:
git pull
Git is just a way for us to share and backup our tools.
Git is a standard. Everyone uses some form of version control.
In the end, you can get by only learning five basic commands.
(On melange) Check out a copy of the repo:
git clone /git/SciFi/
(Not on melange) Check out a copy of the repo:
git clone username@melange:/git/SciFi/
Add a new file:
git add /path/to/new_file.py
Make a change:
git commit /path/to/new_file.py -m "SHORT message, explaining what you did"
Share your changes:
git push
Get everyone else's new changes:
git pull
- My 'git push' didn't work!
- Try doing a
git pull
first. Git likes you to have an up-to-date copy of everything before you push.
- How do I create a directory in Git?
- Don't worry about it. If you create a new file inside a new directory, git will automatically create the directory for you. (You can't create an empty directory.)
If you don't like the command line, you can use a Graphical Interface, after you've checked out the repository into your own area:
git gui
If you need more help, Google is full of great information on Git:
http://wiki.freegeek.org/index.php/Git_for_dummies
http://code.tutsplus.com/tutorials/easy-version-control-with-git--net-7449