Reference, Source Control

How to Push to GitLab

This is mostly a post for me to use as reference because I recently found myself needing to push a project to my self hosted GitLab server but had completely forgotten how to do that from the command line. I use a Mac by the way but the process should be similar on any Linux distro and even windows as long as you have the Git client installed.

To begin you’d need to create a project on GitLab. This process is pretty much the same on either the GitLab site or your self hosted server.

Make sure that you leave the Initializations repository with a README unchecked. If you check this box then you’ll need to PULL the repository down before you can add your project. This would just add a little more complexity.

You’ll want to take note of your Project URL and Project slug, these will be important later.

Click on Create Project.

The next page gives you some basic info on how to push a project.

You’ll see here the section about Push an existing folder. This is what we want.

So command window / terminal you’ll need to change to the directory containing your project.

You might want to add a README.md file before you start.

There are tons of tutorials online about how to do that.

Once you’re in the folder that contains your project you’ll want to initialize your folder and create your local git repository, you do this by issuing the command below.

git init

Next we’ll need to add our remote repository, you do this by using the Project URL and Project slug you noted above which is also shown to you in the Push an existing folder section on Gitlab

git remote add origin https://git.fletchnet.xyz/cfletcher32/test.git

Now that we have the remote repository added we can add the contents of the directory to our local repository. You’ll want to do this anytime you add a new file

git add .

Next we need to commit all the changes to our local repository. You would do this anytime you make any changes to any files. The -m command adds a note to describe what the commit was for.

git commit -m "Initial Commit"

Finally we can push our local repository to our remote repository.

git push -u origin master

You may be prompted for your username and password. After you enter your credentials, git will push the repository.

At any time during this process you can check status by using the following command

git status

Well there it is. I hope this helps someone else. In hindsight if I would have just gone through and created a gitlab project and realized that the instructions were right there infront of me then I wouldn’t have had to look for how to do this Google.

 

 

 

 

Tagged , , , , , , ,

Leave a Reply