Git trying to push non existent repository - reactjs

I installed a new react app in Visual Studio Code and tried to push it to my git repository from local.
After "git add -A", "git commit -m "Initial commit" and "git push --set-upstream origin master" I get an error that it can't be pushed.
fatal: 'https//github.com/UserName/SomeOldProject' does not appear to
be a git repository
This "SomeOldProject" doesn't exist for a while now because I deleted it a few months ago from local and my git repo. I don't know where this comes from. I already deleted "create-react-app" and re-installed it but nothing changed.
I also had the problem that some old and deleted repositories showed up on local after I installed "create-react-app". Still don't know where this comes from, because I deleted most of them a long time ago.
Is there anything I can do here to clear some cache or something else so it won't track all the old files?

Are you sure is a remote configured in this repository?
Try this command:
git remote -v
This command should list your configured repositories, and check if exists a repository configured or if it's right.
If you need to add a new repository to your project, try this command:
git remote add origin <git_url>
This command add a new git repository using orgin (default name) as alias.
Look this tutorial to understand more about remotes: https://www.atlassian.com/git/tutorials/syncing

Related

How do I change the github repo my React app is connected to?

I was trying to add my react project to github when I accidentally spelled my username wrong in the terminal. Now whenever I try to add the project to a repository it says it cannot find the repository, the one where I spelled my username wrong. How can I change which repository my project is being pushed into? I am new to using Git and Github.
You don't need to change the GitHub repository if you only made a mistake in the username.
You need to drop the wrong authorization from credential helper.
echo "url=https://github.com" | git credential reject
Then repeat git push. And don't forget that instead of a password you should enter your personal access token.
I believe you should change the remote URL of the local repo.
git remote set-url <remote_name> <remote_url>
Example:
git remote set-url origin https://git-repo/new-repository.git
More info on this can be found here
Other than that, I would recommend deleting your .git folder in the root of your project and start all over again.
If your app is connected to the wrong remote repo you can connect it again:
first check your remote:
git remote -v
The output will look something like this (<shortname> <url>), e.g.:
origin https://github.com/user/repo_name.git (fetch)
origin https://github.com/user/repo_name.git (push)
if that is the one with the wrong name in it you can remove that connection:
git remote rm <short-name>
Then you can add a new remote with the right spelling in it, e.g.:
git remote add origin <url>

Problems when it comes to committing changes to git after running 'npm run deploy' on my react app

So I have successfully deployed my react project on GitHub pages, there are a lot of useful guides on how to do this. However I am having issues when it comes to updating the project (it is harder to find good guides on this)
So lets say I make a change to my project on the code as it exists in folders on my computer.
Then I will run 'npm run deploy'. After doing this, I can see my changes have been successfully implemented on my online deployed site, so all good.
Then I run the following code to push the changes into the repository:
git add .
git commit -m "update"
That works fine, but I get an error at the next step:
git push -u origin master
When I do this I always get the same error message in the terminal:
error: failed to push some refs to 'https://github.com/redacted/redacted.github.io.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Can anyone please explain what is happening here, and what this error message means.
In the error message, does 'remote' mean the code as it exists in the GitHub repo, and 'local' mean the code on my computer? Why does the remote code and local code diverge after running 'npm run deploy'? In future, what is the best way for me to update the repository so that I don't keep running into this problem.
If it's important, here are my scripts on the package.json file:
"predeploy": "npm run build",
"deploy": "gh-pages -b master -d build",
hint: Updates were rejected because the remote contains work that you do
not [...] have locally.
There are commits on the remote that you don't have locally. To see them, you can use git diff. First, update the local representation of remote references in your repo:
git fetch
Now that you have an up-to-date local representation of what's on origin/master, you can see the differences with:
git diff origin/master
Git diff is one of the most important parts of the git tooling, so become acquainted with its syntax. This should show you what changes you've missed. you can also pull up the log of origin/master which will show the commit messages, authors, and dates with:
git log origin/master
If this loads up in an editor you don't recognize and the lower left of the screen is a : colon character, type q to quit. This program is called less.
All that helps you introspect the remote changes that you haven't incorporated locally. When you're ready to pull them into your own branch, simply issue:
git pull
This will apply missing commits to your local branch. If the local commits change the same lines as the remote commits, you'll end up with a git conflict. In this case you'll have to look at the conflicts and decide how to combine the two changes. Often, remote changes can be incorporated without causing any conflicts, but of course it depends on what's been changed on both sides.
A final note. What you absolutely do not want to do is git push -f. This will force push your changes to master, replacing its current history - in other words, you'll destroy the remote changes. Never do this. There's a time and a place for it, and once you get more comfortable with git diff and its behavior as a distributed change control system, you can revisit that advice.

Deleting some files from project downloaded from GitHub if I want to put the project in another GitHub repository and to push the commits there?

From November 2019 to May 2020 I've been creating Project A on Computer A and I've been pushing the commits into Repository A in GitHub.
Some days ago I downloaded Project A from Repository A as a zip file on Computer B. I want to continue the developing of Project A on Computer B and to stop pushing the commits into Repository A in GitHub and to create Repository B in GitHub and when I make some changes to push the commits there.
Do I have to delete some files from the downloaded Project A before putting it into Repository B so I don't get errors when I put it into Repository B and when I start making commits in that repository?
If you have downloaded the repository as a zip, you have only downloaded a snapshot of repo A HEAD, not all its commit.
That means, on computer B, as you have to do (once you have created a new empty repository B on GitHub) is:
extract repoA.zip
cd repoA
git config --global init.defaultBranch main
git init .
git remote add origin https://github.com/<me>/repoB
git add .
At this point, you can add everything: .gitignore, .gitattributes, .gitmodules, ... All those files are part of the repository.
git commit -m "Inport repoA"
git push -u origin main

How to get `git-p4 sync` to work?

I've successfully created a git branch called 'scaffold' by using git-p4.py clone.
I now want to sync the latest Perforce changes into the git branch so I'm trying git-p4.py sync --branch=scaffold but all that happens is the output of the following:
Syncing with origin first, using "git fetch origin"
Creating/updating branch(es) in refs/remotes/p4/ based on origin branch(es)
Performing incremental import into scaffold git branch
Depot paths: //depot/depot/path/to/code/
No changes to import!
After that, git status says nothing to commit (working directory clean).
How do I get this to work?
The following worked for me on my desktop but fails with fast-import failed on Jenkins:
git checkout scaffold
git p4 sync --branch=scaffold //depot/path/to/code/...#all
git push ssh://git#example.com:7999/repository/project.git +remotes/p4/scaffold:scaffold

libgit2 push... update workcopy after push?

I am trying to push my local changes to a remote git repository. I am using code, which more or less resembles this one here:
How to push git repository through ssh using libgit2
And it works. I can add a file, commit it and push it to the remote repository. When I clone the remote repository everything is as I would expect it. However, there seems to be one little detail, which I am missing.
When I do a 'git status' on my local, I get:
Your branch is ahead of 'origin/master' by 1 commit.
I can do a 'git push; and get as response 'Everything up to date'. After that the 'Your branch...' message is gone.
The local repository does not seem to get notified about the push, even though it is done correctly.
What else do I have to do?

Resources