Difference between revisions of "Git FAQs"

From Genome Analysis Wiki
Jump to navigationJump to search
Line 1: Line 1:
 +
== Turn an already existing directory into a Git Repository ==
 +
 
Its easy to turn an already existing directory into its own repository.
 
Its easy to turn an already existing directory into its own repository.
  
Line 14: Line 16:
  
  
Follow this link if you want to [[Create a remote bare Git repository for a repository to push to/pull from|create a remote bare Git repository for this repository to push to/pull from]]
+
Continue to the next section if you want to create a bare repository for it to push to/pull from.
 +
 
 +
== Create a remote bare Git repository for a repository to push to/pull from ==
 +
 
 +
# cd to where you want the remote repository located.
 +
# Create the bare repository.
 +
#* <code>git init --bare --shared ''bareRepoName''</code>
 +
# cd to your repository that you want link to this bare repository.
 +
# Set the remote.
 +
#* <code>git remote add origin ''path to/url for your bare repository''</code>
 +
# Set the configuration for pulling.
 +
#* <code>git config branch.master.remote origin</code>
 +
#* <code>git config branch.master.merge refs/heads/master</code>
 +
# Push your files to the bare repository (must specify origin master since this is the first push to the empty repository)
 +
#* <code>git push origin master</code>
 +
 
 +
You can now operate as if you had cloned from bareRepoName.

Revision as of 18:07, 14 July 2011

Turn an already existing directory into a Git Repository

Its easy to turn an already existing directory into its own repository.

  1. cd into your directory.
  2. Tell git to create a repository:
    • git init
  3. Add all your files to the repository:
    • git add .
  4. Check that you didn't add any undesired files:
    • git status
  5. Remove any undesired files (if necessary):
    • git reset HEAD filename1 filename2
  6. Commit the files:
    • git commit -m Initialize the repository with all the files


Continue to the next section if you want to create a bare repository for it to push to/pull from.

Create a remote bare Git repository for a repository to push to/pull from

  1. cd to where you want the remote repository located.
  2. Create the bare repository.
    • git init --bare --shared bareRepoName
  3. cd to your repository that you want link to this bare repository.
  4. Set the remote.
    • git remote add origin path to/url for your bare repository
  5. Set the configuration for pulling.
    • git config branch.master.remote origin
    • git config branch.master.merge refs/heads/master
  6. Push your files to the bare repository (must specify origin master since this is the first push to the empty repository)
    • git push origin master

You can now operate as if you had cloned from bareRepoName.