Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push single file in directory to github new repository?

Tags:

git

github

I currently have a file in a repo and have created a new repo, but cannot get the file on the new repo without pushing the entire contents of the directory along with it. I would like to push just the single file from the directory not all of the other contents. I have been doing

git add mygame.rb
git commit -m 'game scores'
git add remote new_origin github.com/etc...
git push new_origin master

After this is done all the from the directory files are uploaded to my new repo even though I never 'added' them with the git add command. All these files are already in my old repo, just basically want to move 1 file to the new repo. git status just returns "# On branch master nothing to commit (working directory clean)"

like image 908
Ordep81 Avatar asked Oct 03 '22 11:10

Ordep81


1 Answers

Your local repo must not be new and therefore when you add a new remote with git remote add... there are other files and history that will get pushed with git push.... This is actually a real cool feature of git.

If you want to start a new remote repository with it's own history and only mygame.rb as a file, you could easily:

mkdir <full_directory_path>
cp mygame.rb <full_directory_path>
cd <full_directory_path>
git init
git add mygame.rb
git commit -m 'game scores'
git remote add origin github.com/etc...
git push origin master:master
like image 170
cforbish Avatar answered Oct 06 '22 06:10

cforbish