Github - How to commit my project to a sub-folder / directory of a existing repository? - github

In Github, i have already a repository, e.g. called "java8"
And under it, i would like to have a sub-folder, e.g. called "01-lambda"
So my folder structure in github should be
java8
01-lambda
02-enums
etc.
Then I want to commit my code to the sub-folder "01-lambda"
How can I do that?
What I tried:
I just created a new folder with a txt file "01-lambda" under the repository "java8", then I tried to commit, but git bash shows they cannot find the sub-file.
I just commit my code directly to repository "java8", but then I need to change path of every files, and add /01-lambda in the path
git init
git add *
git commit -m “my first repo”
git remote add github .git
git remote -v
git push -f github master

I just created a new folder with a txt file "01-lambda" under the repository "java8", then i tried to commit, but git bash shows they cannot find the sub-file.
You need to add before committing, assuming you do have a file inside the new folder (Git would not add just a folder):
git add 01-lambda
git commit -m "add 01-lambda"

Related

How do I remove this folder from my github?

I'm a beginner to using github and I accidentally added this folder to my github but I cannot find a way to remove this please help.
I tried deleting this folder from my main folder and redoing my git pull and push and in the terminal it said that this file as already been removed. But once I pushed my file again the files that needed to be updated were updated but the folder is still on my github repo.
Try:
git rm -r <folder>
git commit -m "remove folder"
git push
The changes will only be saved when you run the commit command

How to upload in an Existing Repository?

I have a repository. I pushed files from a folder. Now I don't want to create new Repository. But I want to push files from a new Folder. The folders are almost same. How can I do this with command?
Assuming that you already have the repository created, you can do the following.
cd newfolder
git clone <link-to-clone-from>
Then copy the files to new folder. Check git status -s to see a summary of changed files in new folder after you copy files. Using git diff or beyondcompare can show you the exact changes that you are about to commit next. If everything looks fine, continue with the next steps
git add -a
git commit -m "your commit message"
git push origin master
Assuming you have two folders:
- Old repo folder
- .git
- My old folders
- My old files.
- New repo folder
- My new folders
- My new files.
And you want to replace all stuff in the remote repo from the old repo folder with the new repo folder.
To do that:
First, delete all content except the folder: .git in the Old repo folder.
Then, copy everything except the folder: .git from the New repo folder to the Old repo folder
And run commands in the Old repo folder:
$ git status
To get if everything is fine. Git will detect that you have replaced a lot of files and deleted many of them. Check the output.
$ git add . && git commit -m "Replace with new content"
$ git push
And this will save your changes and send it to remote server.

How to push code to root of git repository (GitHub)

I am very new to git and have been facing the problem below for 4-5 days now.
I have a project that I want to share on GitHub and I created a repo (https://github.com/jitix/cfs/tree/master/cfs) for the same.
Here is what I did:
Checked out the code from svn using Eclipse (Juno).
Removed svn related files and 'cleaned' the folder by doing Team > Disconnect.
Created a local git repository (using both via eclipse and cli on different occasions).
Added appropriate .gitignore file.
Committed the code into the local repo (somehow eclipse moves the folder there, but not an issue). Eclipse made me choose the $repo/cfs as the folder where the code is committed. I could not commit it to $repo.
Now I want to push it into GitHub. Tried out the following:
Method 1 (eclipse):
Team > Remote > Push
Use refs/heads/master as both source ref and dest ref and commit.
Method 2 (cli from the $repo/cfs directory):
git remote add origin jitix#https://github.com/jitix/cfs.git
git push -u origin master
Issue:
In both cases, I am getting the cfs directory under the GitHub repo, not at the root (as most projects have). Also, each folder has a .. link to the parent folder in it (something that I have never seen on GitHub, and something that does not happen if I push using svn).
I checked out my code from svn, created a local repo and committed the code into
You need to create the git repository inside the folder that you want to upload. You've created it one level above the cfs folder and then pushed that, you want to run git init while inside cfs and then go from there.
Try in commandline instead using eclipse and follow the steps that GitHub recommends.
Go inside the directory of your project and type:
git init
git commit -a -m "first commit"
git remote add origin jitix#https://github.com/jitix/cfs.git
git push -u origin master
It should work, although is pretty much what you were doing.

github uploading project issue

I created a github new repository first in github webpage and then I opened Git Bash to upload folders to this repository. I first used $cd f: and $ git clone git#github.com:username/project name.git to create a folder(with a initial .git folder and a README file in it) in f disk. Then, I used $cd f:\project name to switch to the current folder. After that, I copied all my project folders to my project name folder in f disk. Finally, I used the following four lines to upload all my project folders to github:
$git add .
$git remote rm origin
$git remote add origin git#github.com:username/project name.git
$git push -u origin master
After I entered the passphrase, Git Bash just showed everything up-to-date. But I refreshed my github repository page, there is nothing but the initial README file. Could someone tell me what the matter is?
You didn't commit after your git add.
git commit -m "first commit"
That is why git considered there was nothing to push: you HEAD was still the same than your remote origin cloned repo.
See Git Basics:
Your git add updating the staging area (index), but only a git commit will update your git directory.

How to commit a folder to gitHub

I am new to GitHub, able to create a README textfile and commit that (from my local machine to github site) but now my problem is, i have one folder and i need to commit that folder to git hub, can any one of you help m e on this.
Try this :
git add myfolder
git commit -m "some message"
git push
git add FOLDERNAME
After that, you can do a normal commit + push as you did it with the README file.
Its very simple. Follow some steps-
Just click on the Upload files button.
Now you can see a window where you can drag or upload the files.
Just drag your required folder and it will upload in the repository (don't click on the choose your files button, it will upload your files only, not folder. )
Try this :
git commit folder_path -m "your comment"
folder_path should full path, something like this ../../../folder_path
Follow this steps to update your folder to GitHub:
Step 1: Navigate to your local repository(folder) that contains your code and initialize it
$ cd folderName (or) $ cd ~/FolderName
$git init
Step 2: Add the folder to be a part of trackable files/folders list in GitRepository
$ git add FolderName/
step 3: Commit the folder(save your changes made) to GitRepository
$ git commit -m "Some Message"
step 4 : connect GitHub to your local machine, Here you add a remote name origin to GitHub Repository. You can get this URL from "Clone or Download" link from your GitHub
$ git remote add origin URL
Step 5: Push the committed files/folders to HitHub repository
$ git push -u origin master
Refresh the GitHub repository and you could save the folder committed to respository.
I hope this would be helpful!!