Updating local folder with new contents from a git repo - github

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

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

How to push changes to old repo to GITHUB after downloading it

I lost my PC data after hard-drive corruption. After that from my github repo i downloaded my code and made some changes and did npm install, but when i tried to push my changes to repo, it is saying there are no currently active repo to push.
How to push my new changes to my old repo?
You should have cloned the repo on your local machine, that way you would have the git initialized. But, for now, you can follow the below steps.
git init
git remote add origin <github repo url>
The first line would initialize the git repo and the second would point it to the online repo you already have.
You could have downloaded the repo with:
git clone <repo url>
but to answer your question:
git init
git add .
git commit -m "init"
git remote add origin <repo url>
you can then verify the remote url with:
git remote -v
after that check If your .gitignore file is there, if not create one and add node_modules/
after that just push it with:
git push -f origin master
just check whether you have set the remote origin correctly.
$ git remote show origin
$ git remote -v
use the above commands to check your remote URL. if it is not set correctly, set the URL again.
$ git remote set-url < your repo URL here >
hope this will work

Why must I run `git init` after `git clone`?

We have a GitHub repository. After I clone that repository I have to do a git init from command line before any Git commands will work. git pull, git checkout, etc. don't work.
As far as I know, git init initializes a new repository. Is it like after cloning I am creating a new repository again?
Here are the commands I'm trying to run:
git clone <url>
git checkout master
You don't have to do git init in this situation¹. As pointed out in the comments, git clone will give you a local repository that you can start using right away.
The problem is that you're not in your repository when you try to run Git commands. By default, git clone puts the repository in a subdirectory with the same name as the repository that was cloned. You must change into that directory to use it:
git clone git#github.com/foo/bar.git
cd bar
Now that you're in bar/ you can interact with your repository.
¹If you do run git init in the parent directory you're in for a confusing time. You'll end up with a repository in the wrong place and an inner repository containing your code. Git's behaviour with nested repositories often doesn't match users' expectations.
After the clone, get into the projects root directory by `cd your-project" then run git commands
In your case what happened was, you cloned the remote repository then didn't change your present working directory to the cloned project, you were in the parent of the cloned repo, since parent repo itself is not a git repository, git complained, you can't run any git commands

How to push eclipse workspace projects to git using GIT CMD desktop application?

I would like to synchronize all my eclipse workspace to a github repository. Please tell me the list of commands to do it.
To access Git commands from CMD. You have to set the PATH Environment Variables to Git's bin directory, mine is C:\Program Files\Git\bin.
Then configure your information for all local repo
git config --global user.name "[name]"
git config --global user.email "[email address]"
Create your repository on GitHub. Then go to your project directory(eclipse workspace projects) git init [project-name] and add all files to staging area git add --all or git add * Then commit it with some message git commit -m “Initial Commit” and then git remote add origin <url> then push your files to GitHub git push origin master
See this GIT CHEAT SHEET to know more...
Updated :
Here is the link to download GIT Cheat Sheet PDF.
Take a look !
GIT CHEAT SHEET
If you cloned your Eclipse workspace from a GitHub repository, all you need to do is
git push origin master
If you didn't, you first need to create an empty repository on GitHub. Then copy and paste the URL at the top of the page for your new repo. From the command line type
git remote add origin <paste URL here>
Now you can use the same git push command as above to push your git history to the new GitHub repo.

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.