Difference between revisions of "Git Tips"

From IARC 207 Wiki
Jump to navigation Jump to search
imported>Brjohnson6
imported>Brjohnson6
Line 176: Line 176:
 
To upload new project to GITHUB from Aptana Studio 3:
 
To upload new project to GITHUB from Aptana Studio 3:
  
<br\>The following directions modify/are from:
+
<br\>The following directions are modified from:
 
<br\>https://aptanastudio.tenderapp.com/discussions/questions/1219-aptana-and-github
 
<br\>https://aptanastudio.tenderapp.com/discussions/questions/1219-aptana-and-github
  

Revision as of 13:12, 20 August 2012

Outline

Location of DataPro on GitHub
To download Git
To use Git from Aptana Studio 3
To install Git Bash for Windows
Some useful Git Bash commands
To deal with creating keys and using them with GitHub
Bob's Git Command Notes
Git CheatSheet
Additional Git commands
Warning
Create repository
Awesome conceptual Git website
To upload new project to GITHUB from Aptana Studio 3

Location of DataPro on GitHub:
	[https://github.com/frankohanlon/DataPro]

To download Git:
	[http://git-scm.com/downloads]

To use Git from Aptana Studio 3:
	First (from Mozilla Firefox, not IE) install Aptana Studio 3:
	http://www.aptana.com/products/studio3/download
	Note that after installing Aptana Studio 3, it will have to be 
        configured to use Pydev:
		
	a) Under the windows menu in Aptana Studio, select preferences then select the python 	interpreter.
	b) Under the windows menu in Aptana Studio, select Open Perspective, then other, then 	pyDev
	c) Keys will have to be created in the Git Bash window.
	d) From the GitBash window,  git init will need to be run from the desired workspace directory
	e) also some git configuring will be required from the Git Bash window:
		   git config --global user.email "me@here.com"
	f) git config --global user.name "Your Name Comes Here"
	g) Also numPy will need to be installed from:
		http://sourceforge.net/projects/numpy/files/NumPy/

  
	To work on and download existing project from GitHub:
		right-click on the PyDev Package Explorer, select the “Import” option, and 
		in the “URI” box that pops up, paste the DataPro from GitHub link:
		git@github.com:frankohanlon/DataPro.git
			(the other box should automatically fill up with corresponding text)

		To use/locate git commands from Aptana Studio 3:
		Right-click on the project, select Team and then the appropriate Git command.


To install Git Bash for Windows:
	http://msysgit.github.com/

	Once Git Bash is installed, the default editor can be changed to notepad:
	$ git config --global core.editor notepad
	

Some useful Git Bash commands:

	$explorer .   	opens  current directory folder from windows explorer
	$explorer~   	opens  home directory folder from windows explorer	
	$pwd  		location of present working directory
	$cd .. 		up a directory
	$./ name.bat	(runs a batch file named “name.bat”)
	$vim name_of_file  	Opens up the vim editor
		(type escape, then  :wq  to get out of the vim editor)
	$cat name_of_file 	lists contents of file
	$cat name_of_file|more	list contents of file page by page
	$touch name_of_file		creates a new empty file named name_of_file		
	$git --version			indicates the version of git



To deal with creating keys and using them with GitHub:

	https://help.github.com/articles/generating-ssh-keys

	Hint: just press return when asked:
		Enter file in which to save the key:
		Enter passphrase (empty for no passphrase):


Bob's Git Command Notes:
	$git status
	$git commit -a		//This only adds and commits modified files, not the new ones
	$git push git@github.com:frankohanlon/DataPro-for-Windows master
	$git push git@github.com:frankohanlon/DataPro master
	$diff DataPro/datapro.py DataPro/datapro.py
	$git remote add origin git@github.com:frankohanlon/DataPro_Sample_Files.git
	$git push git@github.com:frankohanlon/DataPro_Sample_Files.git 

Git CheatSheet:
	Click between the narrow vertical lines to see what commands are available from state to state.

	http://ndpsoftware.com/git-cheatsheet.html


Additional Git commands:
	$gitk			Visualize branch history, commits	
	$git diff		between working directory 	
	$git diff --cached	between added and previous commit 
	$git add filename
	$git add filename1 filename2
	$git commit -m 'some silly message'  		-m stands for message
	$git log
	$git pull [remote name]	merges what is pulled in		
	$git fetch [remote name]	does not merge what is fetched.	
	The following will NOT work with Github:
		$git clone git://github.com:bryanj007/NewTutorial.git
			creates NewTutorial folder in the current directory with files in it from GitHub
		$git clone git://github.com:bryanj007/NewTutorial.git funky
			creates funky folder in the current directory with files in it from GitHub 
			NewTutorial project

	Solution to clone issue:
		$git clone git@github.com:bryanj007/NewTutorial.git
        creates NewTutorial folder in the current directory with files in it from GitHub

 	If accidentally use git protocol, will need to change URL of origin:
		git remote set-url origin git@github.com:my_user_name/my_repo.git

		OR since git protocol not supported in GITHUB:

		in .git/config file:
		can make the following change:

		before:
		[remote "origin"]
	    	fetch = +refs/heads/*:refs/remotes/origin/*
    		url = git://github.com/my_user_name/my_repo.git

		after:
		[remote "origin"]
	    	fetch = +refs/heads/*:refs/remotes/origin/*
		url = git@github.com:my_user_name/my_repo.git


		
	
Warning:

	It's somewhat difficult to remove files and folders from repository once posted to GITHUB
	Nevertheless, here's how to do it:
	https://help.github.com/articles/remove-sensitive-data



Create repository:
	mkdir [project]
	cd [project]
	git init 		//This creates a .git directory in the project folder


Awesome conceptual Git website:
	http://www.sbf5.com/~cduan/technical/git/git-1.shtml

	What is in a commit object?
		It has a pointer to the parent commit
		Contains a set of files, reflecting project's state at a given time.
		Contains a 40-character SHA1 name



To upload new project to GITHUB from Aptana Studio 3:

<br\>The following directions are modified from: <br\>https://aptanastudio.tenderapp.com/discussions/questions/1219-aptana-and-github

Basically, you follow this process:
  1. Create a new project
  2. Right-click on project..."Team > Share Project". Commit your local contents to that repo
  3. Create a new Github repo
  4. From Aptana studio, right-click "Add remote" and paste in the URL of your project<br\>(Team-> Remotes-->Add Remote)
  5. $git status
  6. $git add src/
  7. You have to follow up with one manual step ATM. Type "git push -u origin master" in the console for the project
  8. You can now push your files up to Github.

Note: I once had a weird error..The error message was something like this:

error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'

It was solved by executing the following commands:

$ touch README
$ git add README
$ git add (all other files)
$ git commit -m 'reinitialized files'
$ git push origin master --force