Skip to content

localRepo

holzkohlengrill edited this page Dec 15, 2023 · 4 revisions

Introduction

Sometimes it is useful to have a local git repository, e.g. if you won't use a public one, or did not trust external providers. Or just because you want to have versioned local code/files.

Start: Step by step from zero

Somewhere you need a folder for your bare repository (= host), e.g. /home/kirk/git (where kirk is your username).

Change to this directory:

cd `/home/kirk/git

Create a local (bare) git repository:

git --bare init enterprise

, where enterprise is your project name.

Now you can clone your repository (say outer_space is your workspace directory for all your amazing projects):

cd outer_space
git clone localhost:/home/kirk/git/enterprise  # or :  git clone /home/kirk/git/enterprise   , I personal like the first more

Windows

  • For me it seems that only the second one works under Windows
  • Pay attention: backslashes have to be escaped; f.ex.: git clone C:\\Users\\marcel\\git\\blah

Now you have cloned an empty repositry, try adding something:

cd enterprise
echo "where no one has gone before" > README.md

git add README.md

First check via status:

git status .

# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	 new file:   README.md

Commit all changes:

git commit  -m "start journey" .

And push -- important! -- to a branch (e.g. master branch):

git push origin master
#
#....
# * [new branch]      master -> master

Porting Repo to github (or maybe bitbucket)

Suppose you hava a local repo (/home/kirk/git/enterprise) and an existing empty github repo (kirk/enterprise.git)

you can migrate the local repo to github with full history:

# Create a temporary directory
mkdir -p tmp

# Clone a clean and bare version of your local repo
git clone --bare localhost:/home/kirk/git/enterprise local_repo

# Clone your (empty) github repo locally:
git clone https://github.com/kirk/enterprise.git github_repo

cd local_repo
git push --mirror https://github.com/kirk/enterprise.git
cd ..

# You can now remove tmp folder manually
Clone this wiki locally