-1

I’m a relative beginner in programming.

A while back, I created a program in Java that calculates a person’s BMI just for learning purposes.

I’m now trying to learn and understand Git and GitHub, but all tutorials I’ve seen so far only deal with creating git repositories for new apps and programs.

Is there a way to create a repository for a pre-existing program to be added to GitHub?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Derek Smith
  • 9
  • 1
  • 2
  • 1
    https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line – 0x5453 Apr 13 '20 at 15:08
  • https://stackoverflow.com/search?q=%5Bgit%5D+push+existing+directory – phd Apr 13 '20 at 15:39

2 Answers2

1

Very simple, create a repository on GitHub and you will see the instructions what to do.

enter image description here


Important

Don't forget to add .gitignore - generate your required one here:

https://gitignore.io

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
1

The command to create a git repository for an existing code base is the same as the one you use to create one for an empty project:

git init

Then you need to add your code to the repo:

git add .

Note this will add all of the files in the current directory. Most likely you don't want to do this. For example any .class or .jar files shouldn't be in the repo. To ignore these files, create a file named .gitignore in your project directory and add the following lines:

*.class
*.jar

Be sure to add any other files that you don't want to include, for example, you can ignore an entire build directory.

Finally, you can commit all your files to the git repository:

git commit

To upload your code to GitHub, you first need to create an empty repository on GitHub. Then you can add that repo as a remote to your local repo:

git remote add <ULR to your GitHub repo>

Finally, you push your code to GitHub:

git push origin master
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268