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
- Download git from http://git-scm.com/downloads
and configure your settings https://help.github.com/articles/set-up-git
- Create a github account if you do not have one (https://github.com/
)
- 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
- Generate SSH key: https://help.github.com/articles/generating-ssh-keys
- Create a Workspace directory where you will locate your repositories in the hardrive
- mkdir /Users/<your_user>/Workspace
- Go to your github account (https://github.com/
) 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”
- 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:
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:
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:
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:
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:
- http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
- https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches
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:
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:
Fetch (if you only want to know if your repository is updated or not) by doing this:
To update your local master branch you do:
To update your own forked repository at github, do: