Git VCS - Cloning & Workflow

Discussion in 'Engineering Concepts' started by pradeep, Dec 7, 2011.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    After Introduction to Git VCS, this is the second installment in the series, here we'll be see how to setup a workflow, copying repositories & maintaining a central repository to help developers/contributors collaborate.

    Cloning



    In most of the other version control systems, checking out is a standard operation which lets you fetch files in a particular saved state. In Git, cloning is the stand operation, where to get files you have to create a clone of the entire repository, it's like mirroring the central repository, after the clone you know what the central repository knows and you need not be dependant on the central repository.

    To clone a remote repository:

    Code:
    $ git clone ssh://user@remote.server:/path/to/repo
    We'll be using SSH to communicate, though native Git protocol can be used but SSH provides more security & user authentication as Git natively lacks access control features.

    Sync Between Computers



    Many of us work on the desktop, sometimes on the laptop & at times from other locations, so, it's a nice idea to have a remote repository containing all the updates, from other collaborators too (if any). For a demonstration, we'll set up a remote repository, and clone, work & update from another computer.

    Initialize a Git repository on you local machine:

    Code:
    $ git init
    $ git add .
    $ git commit -m 'First commit'
    On the remoter server, setup a bare repository somewhere:

    Code:
    $ mkdir -p /path/to/repo/myproject.git
    $ cd /path/to/repo/myproject.git
    $ git init --bare
    Now let's push our project files to the remote repository from local computer:

    Code:
    $ git push ssh://user@remote.server:/path/to/repo/myproject.git HEAD
    If your colleague or any collaborator wants to checkout the source, they type:

    Code:
    $ git clone ssh://user@remote.server:/path/to/repo/myproject.git
    After making changes, to save changes locally, they type:

    Code:
    $ git commit -a -m 'Made required changes'
    Update changes from the remote server:

    Code:
    $ git pull
    In case of any merge conflicts, resolve them and commit again:

    Code:
    $ git commit -a
    To update/check-in changes to the remote repository:

    Code:
    $ git push origin master
    origin is an remote automatically created pointing to source you cloned from, and master is the default branch in any git repository, we'll come to branches some other time.

    This way, developers at different locations work locally & update to central repository and other update to the latest changes from there, making each developer independent and at the same time providing updates of changes by other developers.

    There many more Git workflows you can choose from, follow this.

    Bare Repositories



    A bare repository is one which does not have a working directory, it only contains the .git directory. It just maintains the versioning data, and no snapshot of files from any version.

    Bare repositories are just like database which are read from and written to, but no one works on them directly. Many git commands do not work on bare repositories.
     
    Last edited: Dec 7, 2011
    gel90 likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice