Push current code to existing GitHub repository - visual-studio

I have several Visual Studio solutions that have both a local repository and one on GitHub. I've already made many changes and successfully pushed those changes to GitHub.
But now Visual Studio has forgotten that one of my local repositories is associated with a GitHub repository and I can't seem to figure out how to reconnect it. In fact, it no longer lists that repository in my list of GitHub repositories.
In the image below, you can see I have a local repository called Toxic, but that repository does not appear in the list of GitHub repositories. If I try publishing the Toxic project to GitHub, it just tells me the repository already exists.
How the heck can I get all of my existing Github repositories to show up in the top section shown above so I can push my latest changes?

it appears the only option is to clone the GitHub repository locally, copy my modified files over the newly created repository, and then check in my changes.
Try fist:
installing Git for Windows (command-line)
cloning your remote repo in a new folder
adding your existing repository as a remote
fetching and see if you can cherry-pick your commits
That is:
git clone https://github.com/<user>/<repo> newFolder
cd newFolder
git remote add old ../path/to/old/local/repo
git fetch old
git log old/master
git cherry-pick old-sha1..old/master
(with old-sha1 being the first commit you want back)
Then add the newFolder in your Visual Studio workspace, and see if everything works (do a modification, add, commit and push)

Unless I'm missing something, it appears the only option is to clone the GitHub repository locally, copy my modified files over the newly created repository, and then check in my changes.
Of course, I lose all my comments and iterations since the last check in to GitHub. And care had to be taken not to delete the .git folder, and to copy over all changed file and delete any that had been removed. Seems like there should be an easier way but this certainly did the trick.

I'm no git expert, but I think I might be able to help, if I'm not too late.
Run:
git remote -v
This should print something in the form of:
origin <remote_repo_url> (fetch)
origin <remote_repo_url> (push)
If you only see:
origin (fetch)
origin (push)
try running:
git remote set-url origin <remote_repo_url>
If you get no output then run:
git remote add origin <remote_repo_url>
And then try
git push -u origin
The -u or --set-upstream flag will set origin as the default repo for your branches.

Related

How to start new Git from scratch when old Git still there

I want to create a new empty repository with git. I cannot find a simple solution online that explains this step.
This documentation states "git-init - Create an empty Git repository or reinitialize an existing one" but then doesn't say which options are needed to make it empty:
https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-init.html
Is a --bare repository the same as an empty repository?
Problem:
I have two different projects with different repo's on github, but when I try to use Git (in Bash) after changing the directory to the new project, it keeps pushing with files from the old project.
I think the problem is that git is using the old repo files and thinks the new folder is just additional files perhaps? Basically I want to start from fresh. Can I just start from scratch on my new project with a new repo?
I have tried $ git init in a new directory, but then it just says: "Reinitialized existing Git repository in /home/user/new_project/.git/"
I tried: $ git remote set-url origin git#github.com:User/New_Project.git
but that just updates where it pushes my new project to, and then includes old projects files.
Please help a noob trying to figure things out the hard way 🙏🏼
Delete .git folder:
rm -rf .git
Then create new git repository:
git init
git remote add origin <remote-URL>
git add .
git commit -m "new clean repo"
git push --force origin master
create 1st project
make git init
create a remote repo for 1st project
link remote repo to 1st project
create 2nd project
make git init
create a remote repo for 2nd project
link remote repo to 2nd project
Git will push everything to its proper remote repo
Small hint from my side
git init : create empty repository and reinitialize an existing one
following link will give more information about different options can be used during git init ($GIT_DIR)
https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-init.html

Reinitializing a git repository

I have an xcode project on my desktop in a directory that originally had a git repository with a tracking branch that tracked a remote branch on github. The remote branch has some 84 commits and is 2 commits ahead of the master branch of the project I'm adding features to. I changed the name of the folder/directory on my desktop. I'm not 100% sure if this is the reason why but when I go to git status I get: fatal: Not a git repository (or any of the parent directories): .git. My plan is to simply git Init, add the remote branch and create a new tracking branch and than commit locally to that branch and than push to the remote branch. However, I'm a git beginner and I'm not sure if this is the proper way to go about it. I'm very weary of losing any commit history or accidentally breaking something. Is the method I outlined a good way of rectifying this loss of the git repo?
If you have all your code updated in remote repo then your local .git is deleted. You don't need to re-init your local repo. Rather just clone it.
git clone remote_repo
If you don't have any commit in remote repo, Simply follow
git init
git add all_local_files
If you have updated remote repo than some commits made in local but not pushed and you lost .git. Simply clone remote. Add all files in a single commit
git clone
git add all_local_files
Looks like you messed up your git repository, but not the code / contents.
One way to restore and keep local changes ( if any ) would be:
Clone another copy of your repo from github.
Copy all modified files to the new repo, omitting removed ones: rsync -duztv /old/local/repo/ /new/local/repo
git status to see what the situation is.

How to recover files in git repository

I had a project connected to a local git repository. I decided to reinit that after some mess with branches and commits. Firstly, I deleted old repository with "rm -r .git", and than created new one with "git init". After that, I found out my work directory looking the same way as if my project was only created - the results of all my work are gone.
Trying many recipes from the internet didn't give results. Please, give me a cue, is there any chance to recover my project's files or not.
In the case your "local repository" means you did git clone /path/to/your/local/repo, yes you can restore it by cloning again with git ckibe /path/to/your/local/repo, or git remote add origin /path/to/your/local/repo && git fetch && git pull origin/master ).
Same thing if you cloned from a remote repository.
Otherwise, there is no way to recover your files with git, except if you removed by a graphical interface (which move to a trash folder instead of making a real deletion) or if you have a back up.

Git Push To New Repo Pushing Wrong Content

I tried creating a new repo on Bitbucket and pushing all of my code to it, but for some reason it is pushing another folder's contents to the repo? I used git status and saw that there were many other files that were untracked yet completely irrelevant.
Things that I done so far -
I have an existing Xcode project
I cd into the folder
I add my origin remote
I git push -u origin --all
I go to Bitbucket and see that another folder of mine has been pushed up
If I use the command ls in my directory, I see that only the files I need are there.
Turns out I hadn't initialized my git repository within that folder....
I used git init and it worked!

How to Set Up Xcode with Remote Git Repository

so I just installed a new remote git repository on one of our servers and want to move our old projects there. Our existing projects have local git repositories, and we can add repos from the server, but how do we move our existing projects onto the server?
Any ideas?
You would do these steps:
Make the individual repositories on the server.
git clone --bare nameofrepo
On the actual repo, add the remote to the repository from which you want to send up work:
git remote add origin <url to your remote>
Now push your branch for your work:
git push origin master
Repeat for any other branches you want to have pushed to the central repo.
The URL in the first command can also be a regular file path. Most solutions, however are through an SSH connection.
After creating your Xcode project, cd to that directory
and make sure you are on the master branch
Type:
git remote add origin <URL-of-your-GitHub-repository>
git pull
git branch --set-upstream-to=origin/master master
git merge
git commit -m "Merging with remote”
git push
Now your new project has been pushed to the remote GitHub directory.

Resources