Difference between revisions of "GIT"
Line 64: | Line 64: | ||
This section will cover the most common processes for getting work done in classes that use Gitorious repositories. | This section will cover the most common processes for getting work done in classes that use Gitorious repositories. | ||
=== Working on Linux machines and /winhomes/ID folder === | === Working on Linux machines and /winhomes/ID folder === | ||
− | If you are directly connected to the login-teer machines, the | + | If you are directly connected to the login-teer machines, the steps below should be the process for doing work for a course that includes a personal repository. |
+ | ==== Initial Setup ==== | ||
+ | * Be sure to set up the repository on Gitorious the way you want it. If it is to be a private / semi-private repository, be sure to: | ||
+ | ** Manage collaborators and add members of teams | ||
+ | ** Manage read access for members and teams | ||
+ | * On Linux, change into the directory above the one you want to create with the respository | ||
+ | * Issue the command | ||
+ | git clone git@gitorious.oit.duke.edu:REPO/REPO.git FOLDER | ||
+ | where '''REPO''' is the name of the Gitorious repository (note that it shows up twice) and '''FOLDER''' is what you want to call the top-level repository folder. | ||
+ | :This should initialize an empty repository in the '''FOLDER''' and then copy the files into it | ||
+ | * Change into that folder | ||
+ | cd FOLDER | ||
+ | * Check to make sure the pull and fetch locations are correct | ||
+ | git remote -v | ||
+ | :You should see that origin is set as the git@gitorious.oit.duke.edu:REPO/REPO.git | ||
+ | |||
+ | ==== General Use ==== | ||
* Change into the appropriate top-level directory for the course | * Change into the appropriate top-level directory for the course | ||
* Issue the '''git pull''' command to make sure the directory is up to date relative to the repository | * Issue the '''git pull''' command to make sure the directory is up to date relative to the repository |
Revision as of 16:23, 6 July 2015
Git is a server based file system that allows group access and collaboration to a set of files. Git takes snapshots of every edit that is committed to the system. This gives the user flexibility to make large changes to the code without losing the previously written code. A majority of Git operations are all performed locally, allowing for files to be saved and edited without an internet connection and pushed to the server when an internet connection is available.
Contents
Still under Development
This page is still under development for the Fall 2015 semester.
Important Commands
The Basics
Before editing files it is important to perform a git pull. This ensures that there are no conflicts between your local files and any files on the git server.
It is good practice to use the following commands after you finish editing your files and exit from the linux environment:
git add .
git commit -a -m 'end of day'
git push
This ensures that all files have been saved and committed to the git server, and that a snapshot of that days work is saved.
Git Add
The command git add . notifies the git server that any new files in the local directory are to be added to the git server. Any time a new file is created this command must be run for git to create a snapshot of the file and allow any nonlocal changes to be pulled.
Git Commit
The command git commit -a -m 'String' commits marks any changes you have made as a snapshot. This does not cause any changes to the git server until the push command is used.
Git Push
The command git push sends any commits that have been completed since the last push to the git server. If there have been any changes to the git files by another user, there will be a prompt to first perform a git pull before pushing the changes to the git server.
Git Pull
The command git pull pulls any commits that have been pushed to the server by another user. If any files have been edited, both locally and by another user since the last git pull, you will be prompted to merge the two files together. Once the files are merged a normal git push can be done if the file is edited again.
Branching
Using Gitorious and TortoiseGit
For Windows users who want to have their files locally on a Windows machine, you can use a program called TortoiseGit to make things easier. Here are the instructions for cloning an already-existing Gitorious repository; this assumes that the repository already exists at Duke's Gitorious server.
Initial Setup
- Download TortoiseGit from [1]; install as recommended
- Download Git for Windows from [2]; install as recommended
- Once both are installed, TortoiseGit can now be accessed by right-clicking in an Explorer window. For the initial set-up, you will want to put your name and e-mail information in:
- Right-click; TortoiseGit -> Settings
- Click the Git section; click the "Global" config source and put in your name and e-mail address; apply and OK.
Public and Private Keys
To access Duke's Gitorious server from your machine through TortoiseGit, you will need to have both public and private keys. The information below is adapted from Using Gitorious, TortoiseGit, and Msysgit Together:
- Run the PuTTYgen program that came with TortoiseGit
- From the Key menu, pick the SSH-2 RSA option
- Click "Generate," then move the mouse around...randomly...
- Once the key is produced, choose a passphrase and confirm it. Note: this passphrase needs to be entered whenever TortoiseGit access your Gitorius repositories, so do not forget the passphrase!
- You will need to do three things: save the public key, save the private key, and post the public key to Gitorious.
- Click "Save public key" - a useful place to save it is Users/YourName/.ssh/id_rsa.pub - note that you need to type in the full id_rsa.pub name; this will not add extensions for you.
- Once that is done, click "Save private key." For this one, you will want to save it in Users/YourName/.ssh/id_rsa.ppk; once again, be sure to include the .ppk at the end in the file name.
- Once that is done, copy the text in the Public key box in the PuTTY Key Generator window. Go to your dashboard at Gitorious, click on "Manage SSH Keys," then in the next window click on "Add SSH Key." Paste the text you copied into the window, then save. Wait a few seconds, then reload the "You SSH Keys" page from Gitorious to make sure it says the key is ready.
Cloning a Repository
Now that the computer you are sitting at has public and private keys and Gitorius is expceting your keys, you can clone a repository from Gitorious onto your computer. Here goes!!
- Decide where you want the new folder to go. If it is on the Desktop, yuo can just right-click on the desktop; if it is somewhere else, create the folder you want in explorer and, while exploring it, right-click to get the context menu.
- Select "Git Clone..."
- For the URL, you will need to go to the project on Gitorius and select the URL from the "Clone and push URLs" section. Paste this into the URL for TortoiseGit
- For the Directory, the program should automatically create a folder with the name of the respository into the folder you right-clicked earlier. If there is some reason you do not like this location, you can change it with the Browse command.
- Here's a critical part - make sure the "Load Putty Key" section is selected. Click the triple-dot box and then go find the id_rsa.ppk private key you generated earlier.
- Click OK. The first time through, the program may ask for the passphrase from your private key.
Common Tasks
This section will cover the most common processes for getting work done in classes that use Gitorious repositories.
Working on Linux machines and /winhomes/ID folder
If you are directly connected to the login-teer machines, the steps below should be the process for doing work for a course that includes a personal repository.
Initial Setup
- Be sure to set up the repository on Gitorious the way you want it. If it is to be a private / semi-private repository, be sure to:
- Manage collaborators and add members of teams
- Manage read access for members and teams
- On Linux, change into the directory above the one you want to create with the respository
- Issue the command
git clone git@gitorious.oit.duke.edu:REPO/REPO.git FOLDER
where REPO is the name of the Gitorious repository (note that it shows up twice) and FOLDER is what you want to call the top-level repository folder.
- This should initialize an empty repository in the FOLDER and then copy the files into it
- Change into that folder
cd FOLDER
- Check to make sure the pull and fetch locations are correct
git remote -v
- You should see that origin is set as the git@gitorious.oit.duke.edu:REPO/REPO.git
General Use
- Change into the appropriate top-level directory for the course
- Issue the git pull command to make sure the directory is up to date relative to the repository
- Do work
- When done working, go back to the top-level directory for the course
- Issue the following commands:
- git add . (this will add any new files you created)
- git commit -a -m 'message' (this will prepare all the files for pushing)
- git push (this will push everything to the repository)