Git - push local repo to a new remote repository - gitlab

I have a group in GitLab which has one repository under it in the remote and all works fine with that. However, I am now trying to create the following scenario:
Create new folder user1 and cd into it
git init
create new file
git add .
git commit -m "msg"
git remote add my-proj https://gitlab.com/my-proj/pro.git
git push --all -u https://gitlab.com/my-proj/pro.git
Sometimes it works and sometimes it doesn't and I can't figure out what I am doing wrong, see example below:
This one worked well:
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/my-proj/user1
$ git init
Initialized empty Git repository in F:/proj-uzip/my-proj/user1/.git/
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/my-proj/user1 (master)
$ git add .
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/my-proj/user1 (master)
$ git commit -m "msg"
[master (root-commit) c98d5d4] msg
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 New Text Document.txt
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/my-proj/user1 (master)
$ git remote add my-proj https://gitlab.com/my-proj/pro.git
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/my-proj/user1 (master)
$ git push --all -u https://gitlab.com/my-proj/pro.git
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 216 bytes | 216.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote:
remote: The private project my-proj/pro was successfully created.
remote:
remote: To configure the remote, run:
remote: git remote add origin https://gitlab.com/my-proj/pro.git
remote:
remote: To view the project, visit:
remote: https://gitlab.com/my-proj/pro
remote:
remote:
remote:
To https://gitlab.com/my-proj/pro.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'https://gitlab.com/my-proj/pro.git'.
This one failed:
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/my-proj/user1 - Copy
$ git init
Initialized empty Git repository in F:/proj-uzip/my-proj/user1 - Copy/.git/
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/my-proj/user1 - Copy (master)
$ git add .
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/my-proj/user1 - Copy (master)
$ git commit -m "hi"
[master (root-commit) 6c9fe76] hi
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 New Text Document.txt
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/elixir-group/user1 - Copy (master)
$ git remote add ty https://gitlab.com/my-proj/ty.git
Gilad#DESKTOP-7SI7CJF MINGW64 /f/proj-uzip/elixir-group/user1 - Copy (master)
$ git push --all -u https://gitlab.com/my-proj/ty.git
remote: You are not allowed to push code to this project.
fatal: unable to access 'https://gitlab.com/my-proj/ty.git/': The requested URL returned error: 403
I did them both one after the other, same process not sure why sometimes it works and sometimes not

It seems like the issue is with GitLab preservation of old deleted repositories. What happened is that my repository was already created some time ago and I deleted it, however, it is still in 'Pending Deletion' state which I assume means that GitLab still sees it as active in some way.
So once I tried to create a new repository with the same name GitLab told me I can't access it, but once I created a new repository that wasn't been created before it worked.
So I guess this is how it works in GitLab but I find it weird that they are working this way.

Related

git push failing with Access denied to Gitlab

I am using git to push my code to Gitlab. Following are the commands I am using
git clone https://<mygitlab.com>/gke-app-namespace-deploy.git
cd gke-app-namespace-deploy
git checkout -b master
git branch
main
* master
git commit -m "first commit"
git remote set-url origin https://<mygitlab.com>/askar/gke-app-ns-deploy.git
$ git push -u origin master
Username for 'https://<mygitlab.com>': askar
Password for 'https://askar':
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://<mygitlab.com>/askar/gke-app-ns-deploy.git/'
The same credentials works while downloading the code but I am getting Access Denied message while uploading the code.
What I am trying to do is clone code from gke-app-namespace-deploy.git' and push to a new repository 'gke-app-ns-deploy.git. Not sure if git by design will allow this.
Try,
git remote add origin https://<access-token-name>:<access-token>#gitlab.com/myuser/myrepo.git
From: https://stackoverflow.com/a/52074198/2675670

git does not commit the backend and the client files becaues they have another git repos inside if them

I finished building the backend (using NodeJS), and the frontend (using ReactJS), but I put them in different repositories. Now, as I am going to deploy them, I arranged them in a specific structure as guided.
final-project
|
---backend <--- restful API
|
---the-tech-blog <--- react app
|
---README
I initialized a new git repository using git init, and I am trying to push everything to this one repository so I can deploy it to Heroku. However, both of my files are committed empty because they have other git repositories inside them.
I read about git submodule and try to add them inside my files:
$ cd ./backend
$ git submodule add -b master https://github.com/MohamadHanafi/theTechBlog-backend
$ cd ..
$ cd ./the-tech-blog
$ git submodule add -b master https://github.com/MohamadHanafi/theTechBlog
I committed again in the main file (final-project), but again nothing changed.

Commit has bugs

I committed a branch and it is merged with master. Later on production, it is found to be bug in the commit.
I need to raise a PR with previous commit of master against master.
I tried the following
git checkout <specific-commit-id>
git checkout -b <new-branch-name>
git push origin <new-branch-name>
When I try to raise PR against master, it says
The source branch is 2 commits behind the target branch
Expected it to allow me to merge it in master but it didn't allow
How can I do so?
Follow the steps below,
git checkout <branch-name>
git checkout -b <new-branch-name> <properly-working-commit-id-of-current-branch-which-we-want-to-deploy>
git add .
git commit --amend -m 'commit-name'
git push origin <branch-name>
By doing so it allows us to merge in GitLab

Error while pushing from bitbucket repo to heroku. It says my repo is a shallow clone

I created a pipeline to deploy my code from Bitbucket repo to Heroku server.
my bitbucket-pipelines.yml
image: node:10.15.3
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- npm install
- git push https://heroku:<my heroku api key>#git.heroku.com/<my heroku app's name>.git HEAD
After pushing my code to my bitbucket repo, the pipeline runs, but fails while pushing the code to heroku git.
Below is the error:
Push rejected, source repository is a shallow clone. Unshallow it with `git fetch --all --unshallow` and try pushing again.
But then by bit bucket repo is not shallow. The command git rev-parse --is-shallow-repository returns false.
You can use the following git command before the push
git filter-branch -- --all
So it would be in your script:
...
- git filter-branch -- --all
- git push https://heroku:<my heroku api key>#git.heroku.com/<my heroku app's name>.git HEAD

Heroku build failing, 'fatal: Not a git repository'

I'm trying to deploy my app to Heroku but keep getting the error
fatal: Not a git repository (or any parent up to mount point /tmp) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).'
Here under the commands I type
$ git branch
-> master
$ git add -A
$ git commit -m'commit'
...your branch is up to date
$ git push
everything-up-to-date
$ heroku create drumbo
Creating ⬢ drumbo... done
https://drumbo.herokuapp.com/ | https://git.heroku.com/drumbo.git
$ heroku buildpacks:set heroku/nodejs
Buildpack set. Next release on sampleapp will use heroku/nodejs.
Run git push heroku master to create a new release using this buildpack.
$ git init (added this in because of https://stackoverflow.com/questions/16853624/git-discovery-across-filesystem-not-set)
Reinitialized existing Git repository in /Users/Berta/Desktop/Codes-senior/sampleapp/.git/
$ git push heroku master
...(fails with) - fatal: Not a git repository (or any parent up to mount parent /home/kozi) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
$ git status
On branch master
your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
$ ls -A
... .git, .github ...
There's also a decent amount of verbiage about npm-merge-driver in the terminal log. Looks like the build fails right after npm install npm-merge-driver is called -
> drumbo#1.0.0 prepare /tmp/build_77f785ef804afd5c02fbe1c7b6f209fd
remote: > npm-merge-driver install
remote:
remote: fatal: Not a git repository (or any parent up to mount
point /tmp)
remote: Stopping at filesystem boundary
(GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
remote:
/tmp/build_77f785ef804afd5c02fbe1c7b6f209fd/node_modules/npm-merge-
driver/node_modules/yargs/yargs.js:1100
However when I uninstalled the npm-merge-driver, build failed because it wasn't found.
What's happening?
Two things - you need to delete the prepare line from your package.json file (should be the line referring to npm-merge-driver,
and you need to make sure you add, commit, and push your code before you run npm run deploy - should clear anything up

Resources