GitLab – Syncing with a Local Repo


In this post I will be creating a project on GitLab and Syncing my local files with it.  Here are links to the previous posts for setting up GitLab and changing the default Labels.

Background

I have a project that I created on GitLab called “Shapes”  that contains a single Readme.txt.  I have a folder called Shapes on my PC that contains a src and a doc folder.  I all of my local files to be part of the repository on the server.

Note:  These steps are not exactly clean so do not follow them exactly.  Meaning I made a couple of mistakes (I’ll point them out as I go along) and blindly following these directions will do what I need, but it was the long way to get there.  I am documenting them for future reference.  Maybe the next time I create a project, I’ll update these instructions to be as small as possible.

Also please note that my experience with git is less than that of GitLab, so every command I found I had to google and/or read about before entering.  Again, I am documenting this for my own purposes.

When starting a project, GitLab offers these few examples as to how to create the repository (It also fills the examples with your exact settings so it is every easy).  However, I could not use these because I had already created an example project with GitLab by adding a Readme.txt and I had code on my PC.  If you are just starting, I suggest using one of their examples.

GitLab Instructions

Git global setup
git config --global user.name "FirstName LastName"
git config --global user.email "email@example.com"

Create a new repository

git clone git@www.stonemillkids.com:username/Shapes.git
cd Shapes
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Existing folder or Git repository

cd existing_folder
git init
git remote add origin git@www.stonemillkids.com:username/Shapes.git
git push -u origin master

What I did

I had a Shapes Readme.txt (If I did not, I could have followed the directions above).  Doing it a 2nd time I might consider deleting the Shapes project from the server and starting over.

On the PC I created a repository and tried to link it to the server.  I did something wrong so the remote did not sync correctly.

$ cd Shapes
$ls
/src /doc
$ git init Shapes

I then checked out the server repository and then merged what I had locally to the remote repository

$ git pull http://www.stonemillkids.com:XX/username/Shapes.git
 Username for 'http://www.stonemillkids.com:XX': username
 Password for 'http://username@www.stonemillkids.com:XX':
 warning: no common commits
 remote: Counting objects: 3, done.
 remote: Total 3 (delta 0), reused 0 (delta 0)
 Unpacking objects: 100% (3/3), done.
 From http://www.stonemillkids.com:XX/username/Shapes
 * branch            HEAD       -> FETCH_HEAD
 Merge made by the 'recursive' strategy.
 Readme.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 Readme.txt
$ git status
 On branch master
 nothing to commit, working directory clean

I then added remote “shapes” to the project, but it already existed locally… See next step.

user@WINDOWS_PC /C/Shapes (master)
$ git remote add shapes http://www.stonemillkids.com:XX/username/Shapes.git
fatal: remote shapes already exists.

Instead I added a new “Stuff” project and pointed that to the remote server

user@WINDOWS_PC /C/Shapes (master)
$ git remote add Stuff http://www.stonemillkids.com:XX/username/Shapes.git

user@WINDOWS_PC /C/Shapes (master)
$ git show
commit f2720716a70029b4f00df8b997e63e23503c34cb
Merge: 199b214 15aa4d4
Author: Greg S <gschallert@gmail.com>
Date:   Mon Jul 13 02:29:03 2015 -0400

Merge http://www.stonemillkids.com:XX/username/Shapes
user@WINDOWS_PC /C/Shapes (master)

I am not sure if the next couple commands are needed, but I wanted to add everything locally to the server

$ git add .

user@WINDOWS_PC /C/Shapes (master)
$ git push Stuff

Username for 'http://www.stonemillkids.com:XX': username
Password for 'http://username@www.stonemillkids.com:XX':
Counting objects: 172, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (139/139), done.
Writing objects: 100% (171/171), 7.58 MiB | 358.00 KiB/s, done.
Total 171 (delta 9), reused 0 (delta 0)
To http://www.stonemillkids.com:XX/username/Shapes.git
15aa4d4..f272071  master -> master

user@WINDOWS_PC /C/Shapes (master)
$

Going back to the GitLab Server, I checked the project and all of the docs and my project code there.

Now progress real coding can begin.

Update:  The “add .” command did not add all of the .xml files from the LibGDX project, so I had to reconfigure LibGDX to make it work. Next time I download a new project I will document that.

Other commands that I might find useful

In investigating how to do the above, I took notes on other examples that might be useful. They are below:

Checking into the server

# setup the remote server that your local branch is pointing to
$ git remote add Stuff http://www.stonemillkids.com:XX/username/Shapes.git
#Check the Changes you made to make sure everything good
$ git status
#Add all of the changes to the commit
$ git add .
#commit the changes locally
$ git commit -a
#Push the changes back to the server
$ git push

Branching into a new project

#Create a Branch "RC1"
$ git checkout -b RC1
Switched to a new branch 'RC1'
#Push the branch to the staging repository
$ git remote add staging http://www.stonemillkids.com:XX/username/Shapes_Staging.git
$ git push stage RC1:RC1

Leave a comment

Your email address will not be published. Required fields are marked *