Personal tools

GIT short instructions

From hpcwiki

Revision as of 15:41, 17 February 2015 by Hpcwiki (Talk | contribs)

Jump to: navigation, search

Contents

Repository creation

  1. Create a directory for the information to be under version control
    mkdir myProject
  2. Open the directory
    cd myProject
  3. Initiate an empty repository
    git init
  4. Add current files to the repository
    git add .
  5. Commit the changes to the repository
    git commit -m "message with a brief description of the changes"


Remote repository creation

  1. Login in the external server via ssh
    ssh username@server-host
  2. Go to repository directory
    cd /var/repo
  3. Create a directory for the information to be under version control
    mkdir myProject.git
  4. Open the directory
    cd myProject.git
  5. Initiate an empty shared bare repository
    git --bare init --share=group

Mirroring to a remote server

  1. Add the external repository
    git remote add origin ssh://username@server-host/var/repo/myProject.git
  2. Push the local files to the repository
    git push origin master

mirroring to the web server

  1. Create a mirror of a bare repository
    git clone --mirror ssh://username@server-host/var/repo/MyProject.git
  2. Update the local content
    git fetch -q --all

Clone a git project

  1. Go to the directory where the project will reside, in this example workspace
    cd workspace
  2. Clone the external project
    git clone ssh://username@server-host/var/repo/myProject.git myProject

Working with git

  1. Change the directory to the project directory, in this case inside workspace directory
    cd workspace/myProject
  2. Obtaining the last committed changes
    git pull
  3. Submitting the local changes to the co-workers
    1. Adding files and modification
      git add .
    2. Committing to the local version
      git commit -m "Message that describe the changes in the project"
    3. Pushing the changes in the external repository
      git push
    4. Branching Git Repository

      The next instructions were taken from the GIT-SCM Branching

      1. Create a new branch
        $ git branch MyBranch
        where MyBranch is the branch to create
      2. Switch to an existing branch, you run the git checkout command. Let’s switch to the new MyBrnach branch:
        $ git checkout MyBranch
      3. A short instruction to create a branch and change to it as a working copy is:
        $ git checkout -b MyBranch
      4. To switch between branches: (in this case to the master or trunk)
        $ git checkout master
      5. To merge a branche with the master:
        $ git checkout master
        $ git merge MyBranche
      6. Now you are ready to delete the merged branche:
        $ git branch -d MyBranche
      7. To push a branche in the repository
        $ git push -u origin MyBranche
      8. To checkout a branch from the repository
        $ git checkout -b MyBranche origin/MyBranche