How to add my current project to an already existing GitHub repository

I'm very new to Git. I've been searching for an answer, but I couldn't find one.

In my computer I have a project folder like this:

project_a --some_folder --another_folder --.git 

And I have a repository on GitHub, let’s say . Under this repository I have some folders. So my goal is to put my project_a under trunk/bin. How do I achieve this? (Again, I'm very very very new.)

9 Answers

Open your Terminal, access to this folder and write:

git init git add . git commit -m "my commit" git remote set-url origin :username/repo.git git push origin master 
8

I had more luck with navigating in my terminal to the directory I wanted to add to the repository, then (assuming you're working on a branch called master):

 git init git add . git commit -m "my commit" git remote add origin <remote repository URL> git push origin master 

Here's a link to an article explaining how to do it in more detail:

Note that you won't be able to run the "git add ." line if the directory in question is open.

3

All the answers above seems to guide about creating a new repository in git but the question is about adding a folder to existing repo. To do that following steps can be followed.

  • Clone your existing repo using following command: git clone
  • Manually take your project folder to the desired location i.e. trunk/bin
  • Now commit and then push in the repo using the commands: git commit -m "message" and git push origin master
1. first create a git repostry. 2. second open git bash in existing or uploading project. 3. perform git init 4. git add . 5. git commit -m "print message" 6. git remote add github<repostry url> 7. git remote -v 8. git push github master 

OR

git push origin master 

if you get any error, you may use it

git push -f origin master 
1

You have to use -f when you are going to push on already existing repo.

git init git add * git commit -m "Initial commit" git branch -M main git remote add origin <repo url> git push -f origin main 
1

I think it is very preferable if you first pull the existing Github repo on the local and then add the new files to the Github repo

This link will help:

Assume that I would like to add FreeRTOS repository, which URL is , into my repository, example URL is as a submodule

git submodule add git add . git commit -m 'add a submodule' git push 

To clone using HTTPS:

git clone --recurse-submodules 

Using SSH:

git clone :username/example.git --recurse-submodules 

If you have downloaded the repo without using the --recurse-submodules argument, you need to run:

git submodule update --init --recursive 

Go to the directory where you code is,

git init git add . git commit -m "Your message" 

Now add your address go to your git hub copy the clone address,

git remote add origin <remote repository URL> 

Now add push your code with,

git push -u -f origin master 

And you are done.

So i had this project that wasnt under source control i made some changes to and wanted to keep stuff i changed.

git init git remote add origin <url> git fetch git branch master origin/master git restore --staged . 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like