Difference between revisions of "GIT"

From PrattWiki
Jump to navigation Jump to search
Line 33: Line 33:
  
 
== Branching ==
 
== 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 [https://gitorious.oit.duke.edu Duke's Gitorious server].
 +
=== Initial Setup ===
 +
* Download TortoiseGit from [https://tortoisegit.org/]; install as recommended
 +
* Download Git for Windows from [https://msysgit.github.io/]; 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 [http://blog.itsnotfound.com/2014/04/using-gitorious-tortoisegit-and-msysgit-together/ 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 [https://gitorious.oit.duke.edu 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.
 +
  
  
 
== Common Errors ==
 
== Common Errors ==

Revision as of 19:21, 4 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.

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.


Common Errors