0

I am new to the git so please be patient with me :)

So I have created a repo in GitLab and I am trying to push the code into the repo.

Steps I used: 1. git clone [project URL]

  1. git init

  2. git remote add origin [project URL]

  3. git add [folder name]

  4. git commit -m [your message]

  5. git push -u origin master

Now when i push the code i get this error

git push -u origin master
To [project URL]
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to [project URL]
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.

My repo :

enter image description here

My directory i wanna push to the repo:

enter image description here

Samanyu Mehra
  • 107
  • 11
  • 1
    You need to pull the latest changes from your `master` branch . try first `git pull origin master` and then commit and push. – Dev-vruper May 17 '21 at 08:42
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+remote+contains+work+that+you+do – phd May 17 '21 at 08:51

1 Answers1

0
  1. Go to the newly created repository.
  2. Select the URL in the top-right section.
  3. Go to the folder where you want to check out the project in the terminal. No need to create a new folder for the project.
  4. Enter the Git clone command, and change the URL to the URL you just copied:

$ git clone URL

  1. You can now go to the folder and check whether it is a Git folder by running the following command

: $ git status

  1. To commit the change, we run the following command:

$ git commit -m "Added readme file"

  1. Now, we have the commit in our local Git repository, but to send it to the GitLab server, we have to enter another command:

$ git push -u origin master