Cloning and pulling from GitLab

From mi-linux
Jump to navigationJump to search

Main Page >> GitLab server >> 2. Cloning and pulling from GitLab

Importing from repository

So far we have explained how to commit (i.e. push) changes from your local repository to the central repository. But what about the other way around? There are 2 git commands for this:

  • git-pull: Pulls a copy of a project from a Git repository server to the local file system and synchronize between the two. Note that in order to pull (or push) a project, you must have either created the project (e.g., using the git init command), or cloned the project (e.g., using the git clone command, see below).
  • git-clone: Creates a copy of a project on your local file system. You can use this command to "import" a project from Gitlab that was not originally created by you (e.g., by your teammates.)


If other team members wishes to work on the repository you created earlier then they will need to "clone" it first:

git clone

The command above:

  • creates a new folder
  • creates the local repository
  • imports all the files from the server to the local repository

You are essentially creating a duplicate working copy of the project locally.

You might make a change to an existing file, or even add new files:

gedit index.html // make a change to the file and save

touch page2.html
git add page2.htm

git commit -m "Commit by team member"
git push -u origin master

The commands above allow you to:

  • make a change to the existing "index.html" file
  • create a new "page2.html" file (empty for now) and add it to the local repository
  • commit all changes to the local repository
  • push all changes back to the server


If you already have a local copy of a repository (you either created it in the first place, or cloned it earlier), and only need to "pull" the latest changes from your team, then you'll need the "git pull" command:

git pull origin

Note: we are reusing the alias we created earlier ("origin"), which is a shortcut for our repository's URL.

The command above will import all new files, as well as existing files that have been updated, into your local repository.

Working as a team

Once all developers have a local copy of your repository, it's a case of simple pulling and pushing changes to and from the central repository.

Next chapter

Solving conflicts on GitLab