Setup Instructions for git and github

In this Twiki you can find a step by step introduction and configuration of git and github on your local machine. It is also explained how to clone a repository into a virtual machine. Basic github commands are introduced. In order to understand this Twiki you need to know basics on shell comand line, you also need to have access permission to the remote machines you intend to use.

First steps

  1. Download git from and configure your settings
  2. Create a github account if you do not have one (
  3. Fork the repositories you need for working. If you are a WMAgent developer, the following could be a good start. Sometimes, you should ask the administrator of the repository to add you. WMAgentScripts has an administrator then you have to ask who is.

Clone a repository to your local machine

  1. Generate SSH key:
  2. Create a Workspace directory where you will locate your repositories in the hardrive
    • mkdir /Users/<your_user>/Workspace
  3. Go to your github account ( and clic on one of the forked repositories. Then in the right part of the window you will see “HTTPS clone URL”, select SSH and copy to the clipboard the contents of “SSH clone URL”
  4. Go to shell (Terminal) and do:
    • cd Workspace/
    • git clone <paste from the clipboard>

github setup for lxplus

Please see the following link How to access to Scripts in the WMAgent.

Adding new/Updating files to the original repository

First go to the repository:

  • cd Workspace/<Name_of_reposiroty>/
Check your current branches with:

  • git branch
Create a new branch and switch to it

  • git checkout -b <name_of_the_new_branch> upstream/master
For checking out to a branch only do git checkout <name_of_the_branch>

Once in your branch you can check the status of the files in your repository doing:

  • git status
This will return something like:

# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
# .metadata/
# .project
# .pydevproject
nothing added to commit but untracked files present (use "git add" to track)

If you have created a new file into your repository, the message above will tell you that a file could be added. For adding do:

  • git add <name and extension of your file>
When you have added a file, you can commit the changes to your branch. For committing do:

  • git commit
If you want to merge your commit to the original repository, you may push the branch with the changes to it. Note: if you are not the owner of the repository, someone else may be the responsible to decide whether your commit can be merged or not. For pushing a file do:

  • git push origin <name_of_the_branch>
After you push a commit into a remote repository: go to the github and login, then create a “pull request”. Pull requests enable management of change and double checking, then it is always a good practice. A pull request is also a space where many developers can contribute and build shared knowledge.

When you want to update a commit that already has a pull request, there is no need to do a pull request again. You may only push the new commit, but this will show all the commits separately. For avoiding this, just modify the last commit you did:

  • git commit --amend
Instead of committing again, you are amending the last commit. Then force push (-f/--force option):

  • git push -f origin <name_of_the_branch>
When the commit has been tested and approved, it can be merged into the original repository. You might not have privileges to do so at the beginning. There is also a developers rule about merging: a pull request may not be merged by the requester.

For additional information clic on:

If you want to become an expert on github, read this:


Upstream set up

There is two remote repositories you are working with: your personal copy (the forked one), and the original.You may have to set the origin and upstream locations with those. Then commits and pull request can be pointed to them. First check your current configuration:

  • git remote -v
It will return the origin location (pointed at your github user). Add the upstream one doing this (Example):

Do git remote -v again. Your origin and upstream locations has been configured.

Updating the files in your local repository

When new commits has been added to a remote repository, you may need to update your local repository. To do this (upstream setting up must be set first: Upstream set up), first point to your local master branch:

  • git checkout master

Fetch (if you only want to know if your repository is updated or not) by doing this:

  • git fetch upstream
To update your local master branch you do:

  • git pull upstream master

To update your own forked repository at github, do:

  • git push origin master
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r5 - 2015-08-25 - JohnHarveyCasallasLeon
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback