Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use git add origin git@anything with new git dir

Tags:

git

gitlab

I have a project in with I am producing many commits, so it's occupied space is growing quickly. Since I have a gitlab page were the commits are pushed, I decided that would be better to get rid of these old commits on my local git directory, as I can always get them from gitlab.

To do so, I simply deleted the local .git dir, and created a new one. I used the sequence

git init 
git add .
git push -m "test"
git add origin git@myGitPage.../myGitPage.git 

but the last command is resulting in

fatal: pathspec 'origin' did not match any files

Then I restored the old .git directory, did some modifications and pushed these to gitlab. Then deleted the local git dir to try again with new git created from scratch, but as expected it did not work once more.

When restoring the old git, I am restoring an old version, since I pushed a new version to gitlab, and now when I send a

git push origin master

with this the old version

I receive a

! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@...' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.

If I download, and then unpack the newest version from gitlab, I receive the same:

fatal: pathspec 'origin' did not match any files

To summon it, with a brand new git dir or the newest version from gilab I receive the above error message. With the already old, I receive the message with mentions fast-foward.

How can I solve all this mess, returning to my routine of

git add .
git push -m "anything"
git push origin master

not needing to keep old commits on my pc, but without erasing them on gitlab?

like image 968
user2752471 Avatar asked Oct 17 '25 12:10

user2752471


1 Answers

The command is git remote add <name> <url>, not git add <name> <url>. git add is a different command.

like image 188
hobbs Avatar answered Oct 20 '25 01:10

hobbs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!