Conner
Conner

Reputation: 413

How do I make existing code a git branch?

I'm very new to git coming from subversion. Our techops team created an empty repo for my new project. I've been working on the project for weeks and have all the code in a folder off my C drive. I've pulled down the empty repo into a new folder. I want to keep that folder "clean" and not work in it. How can I make my existing code into a branch of the now empty repo folder? Please excuse the terminology. I'm very new to this.

Upvotes: 0

Views: 51

Answers (3)

Johnny Z
Johnny Z

Reputation: 15449

One concept you will have to get in your head coming from subversion is that there is no difference between a git repo on your local machine, and a git repo on the server. The state that you are trying to achieve is to have two git repositories, both with your code, with one git repo being on the server, and one being on your local machine. Also, the server repo, will be linked to your local repo.

The link allows you to do git push (when you have changes on local not on the server), or git pull (when there are changes on the server not on local.)

So having said this there are different ways to achieve this state. I recommend doing this.

git clone <server git url> -> Creates a git repo equal to the server repo. The server repo is obviously empty, but doing a "clone" will create that link between local and remote.

cp C:\source_code <cloned git repo>

cd <path to git cloned repo>

git add

git commit

git push

Upvotes: 0

Chiron
Chiron

Reputation: 20245

You start with moving your source files into the empty folder (which I supposed it contains/will contain your Git repository . Then it is time to explore the add command (this is called staging).

 git help add

After you staged your files, it is time to commit them to your local repository.

git help commit

I heartily recommend to read this free excellent book: Pro Git

But any way, do you want to keep your master branch empty? Or your current code is going to be the master? Sorry but your question is not clear regarding this point.

Upvotes: 1

Frederic Nault
Frederic Nault

Reputation: 996

You have to create an authoritative repository from your repository.

Once it is done, clone it with --no-hardlinks as an option.

You will end up with a working copy. You will be able to do branch,tag,..

Upvotes: 0

Related Questions