How do I create a project in Gitlab using git?

Asked

Viewed 4,787 times

4

We can easily create a project on Gitlab and "sync it" by git:

$ git clone [email protected]:user/teste.git

But to do otherwise?

Create folder and local project, and send as a "new" in the Gitlab?

  • On Github, I do the local and remote repository, and then send a first commit

  • @mutlei But the commit is only local. It does not send to Gitlab...

  • Yes. Then you push to send the commit to the remote.

1 answer

4


I think you’re talking about sending a remote repository to an existing project.

Local Repository of Zero

I usually do like this:

  • I create the project folder
  • I start the local repository inside the folder I just created. The command is git init
  • After that, add the files that will be uploaded to the first commit. Run git add . to select all files (optional, if you want to do one by one you can, it’s just an example)
  • Commit. git commit -m "primeiro commit"
  • Add the source location. git remote add origin [email protected]:user/teste.git
  • Push home to your server: git push -u origin master

Ready, you are sending the site data from an existing repository on your machine.

Summary of what I did above, through BASH:

>>> mkdir projeto
>>> cd projeto
>>> git init 
>>> git add .
>>> git commit -m "primeiro commit"
>>> git remote add origin [email protected]:user/teste.git
>>> git push -u origin master

Local repository with existing origin

If you are trying to use an existing repository that has another source, you will not be able to use the command git remote add origin. In that case, use git remote set-url origin [email protected]:user/teste.git, but only if you already have a repository with origin, and not if you’ve created one from scratch.

Then just do the git push -u origin master.

Explaining the commands

git-init

Starts a repository git. By running this command, you’re saying that, from now on, that directory will have GIT version control.

git-add

Adds the contents of one or more files to the change index. When you do git add readme.txt, is saying that the changes made in readme.txt will be saved to the next commit.

I like to wear git add and keep adding the changes I made according to a topic.

For example:

I created a button on the user registration page that checks if the email is valid. For this, I created the button on criar-usuario.html and in criar-usuario.js I made the ajax call that will make that query.

You can do so to process the modifications:

 >>> git add views/criar-usuario.html js/criar-usuario.js

Then when you do the commit, only the two files will be added to the list of modifications.

When using the dot (git add .), you are saying that all files will be added.

git commit -m

Processes the changes reported in git add and adds to the change history. In the above case, the flag -m indicates that you are entering the commit message directly in the command call. If you use only git commit, a window that usually uses the vim or the nano (common code editor on Linux) will open for you to post the message from commit.

Commit messages need to describe what you’ve done.

Using the previous example:

>>> git add js/cadastro-usuario.js views/cadastro-usuario.html
>>> git commit -m "Adicionando botão de consulta de e-mail"

git remote add origin url_do_repostiório

You’re saying that the place where you’ll be saving your GIT changes remotely will be the URL you’re told.

This command is usually used when you create a repository with git init, because it just adds version control. The git remote add origin informs the server where you will save the changes.

git push -u origin master

The git push sends the commit information you created to the server. Commits are being added to the queue and you can see which ones were not sent via the command git status.

The -u is usually used in the first commit and the origin master indicates that the branch of origin will be the master. The master is usually the branch standard of GIT.

I’m not going to dwell too long on Branchs. Read about it here:

  • The remote add was missing! Dude, what is this origin? That would be the briefcase I’m in?

  • @Rbz origin is the remote repository.

  • @Rbz takes a look at the summary (the commands)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.