当前位置: 动力学知识库 > 问答 > 编程问答 >

How to convert existing non-empty directory into a Git working directory and push files to a remote repository

问题描述:

  1. I have a non-empty directory (eg /etc/something) with files that cannot be renamed, moved, or deleted.

  2. I want to check this directory into git in place.

  3. I want to be able to push the state of this repository to a remote repository (on another machine) using "git push" or something similar.

This is trivial using Subversion (currently we do it using Subversion) using:

svn mkdir <url> -m <msg>

cd <localdir>

svn co <url> .

svn add <files etc>

svn commit -m <msg>

What is the git equivalent?

Can I "git clone" into an empty directory and simply move the .git directory and have everything work?

网友答案:

Given you've set up a git daemon on <url> and an empty repository:

cd <localdir>
git init
git add .
git commit -m 'message'
git remote add origin <url>
git push -u origin master
网友答案:

Here's my solution:

git init
git remote add origin PATH/TO/REPO
git fetch
git checkout -t origin/master
网友答案:

In case the remote repository is not empty (this is the case if you are using IBM DevOps on hub.jazz.net) then you need to use the following sequence:

cd <localDir>
git init
git add -A .
git pull <url> master
git commit -m "message"
git remote add origin <url>
git push

EDIT 30th Jan 17: Please see comments below, make sure you are on the correct repo!

分享给朋友:
您可能感兴趣的文章:
随机阅读: