Saturday, December 21, 2013

How to Push to a Local Repository Using Git

Typically I needed to push to a local repository when the remote one in our office was temporarily unavailable. 

Suppose you have got a project called My_Project and use Git for source code management. If you would like ti set up a repository on your local machine to push to it, this guide can be useful to you.

Let's start.
  1. Go to the directory with your project.
  2. Init a repository in this directory using git init
  3. After changing some files, commit them using git add -A and git commit -m "Initial commit"
  4. Create a directory called My_Repo.git on your local machine. It will be your local repository. Let's create it in the home directory.
  5. Go to My_Repo.git.
  6. Run git init --bare
  7. Go back to the My_Project
  8. Add the full path of My_Repo.git to a list of repositories of your project. 
git remote add local /home/maksim-dmitriev/My_Repo.git

You are ready to push to your local repository.

git push local master

And then push, clone, and pull as usual.

No comments:

Post a Comment