github uploading project issue - github

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.

Related

Git push creates my project folder inside another folder, how to avoid it?

I have been creating some repositories of my projects since the terminal and everything was good, but recently I tried to push a project to GitHub and but another folders are created.
For example, the path of my project folder is /Desktop/Programming_course/React_Native/robotreact.
So, since the terminal I go to the path of my Project robotreact and I run:
git add .
git commit -m "first commit"
Then, in GitHub, I create my repository and after that I run:
git remote add origin https://github.com/Josesosa0777/robotreact.git
when I push it running: git push -u origin main
In my GitHub are created other folders:
How can I avoid those extra folders?
It seems like if another project is added, I am not sure if the problem is about a SSH key, I dont know how to solve it, any idea?
That means you have initialized your Git repository in / instead of /Desktop/Programming_course/React_Native/robotreact: check for /.git
If that is the case, and you don't have many commits, you can simply:
delete /.git
initialize the repository in the right folder,
add the remote origin
add files, commit and push
That is:
cd /Desktop/Programming_course/React_Native/robotreact
git init .
git remote add origin https://github.com/Josesosa0777/robotreact.git
# check your user.name/user.email
git config user.name
git config user.email
git add .
git commit -m "First import"
git push -u origin main
If your local branch is master:
git push -u origin master:main

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

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"

Updating local folder with new contents from a git repo

I cloned a git repo into my pc using this command in my git bash
git clone https://github.com/xxx/yyy.git
which created a folder called yyy in my pc.
How can I update the folder yyy in my pc with new contents of the https://github.com/xxx/yyy.git (is it called remote repo)?
I followed the instructions in Updating a local repository with changes from a Github repository, in particular git pull origin master but none of them worked and returned the error $ git pull origin master
fatal: Not a git repository (or any of the parent directories): .git.
I also tried git pull https://github.com/xxx/yyy.git as I reasoned that if I successfully did git clone https://github.com/xxx/yyy.git, the git pull https://github.com/xxx/yyy.git must work otherwise git syntax is not great.
Should I do the "clone" again to overwrite the existing folder in my pc? Why can't I do "pull"?
You need to issue git commands from within the cloned repository:
cd yyy
git pull
You are probably executing this command from outside the yyy folder. You have to go into it first:
cd yyy
git pull

push my project to github

I followed these steps: https://help.github.com/articles/generating-ssh-keys
now, I want to create a folder in my github account, is called: "TODO_LIST", and push my project into this folder.
what I should do? I'm located in the folder I want to add.
should I need to do something like the next following?
$ git init
$ git add .
$ git commit -m 'first import'
$ git remote add origin git#github.com:alonshmiel/TODO_LIST.git
$ git push origin master
p.s, I have two SSH keys in my account because I push from two computers.
This is explained in the Create a Repo help page:
Every time you make a commit with Git, it is stored in a repository (a.k.a. "repo"). To put your project up on GitHub, you'll need to have a GitHub repository for it to live in.
[...]
Click New Repository.
Fill out the information on this page. When you're done, click "Create Repository."
[...]
git init
# Sets up the necessary Git files
git add README
# Stages your README file, adding it to the list of files to be committed
git commit -m 'first commit'
# Commits your files, adding the message "first commit"
[...]
git remote add origin https://github.com/username/Hello-World.git
# Creates a remote named "origin" pointing at your GitHub repo
git push origin master
# Sends your commits in the "master" branch to GitHub

Github Showing Parent Directories

I have a website I'm developing, it's github is https://github.com/samclark2015/Project-Emerald. I have the repo under my user folder in a subdirectory. Now when I push the site to github, it updates the tree as Sites/Project Emerald/... I need the contents of the project emerald folder in the root of my github repo. How can I change the root of my repo on my PC?
Since you just did your first commit in your GitHub repo, the easiest way would be to:
delete your local .git directory you have under 'Site'
recreate your repo locally, and force push it:
That would give:
# in Site/Project-Emerald
git init .
git add remote origin https://samclark2015#github.com/samclark2015/Project-Emerald.git
git add .
git commit -m "first commit, again"
git push -force origin master
You would then see in your GitHub repo directly:
PHP
SpryAssets
pictures
README
config.inc
...
Other alternatives are mentioned in "My Git repository is in the wrong root directory. Can I move it? (../ instead of ./)"