Git - gher-uliege/Documentation GitHub Wiki
Git is a version control system (VCS).
Installation
The procedure is described for Linux, Mac and Windows on the main git documentation: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
Configuration
Display current branch in bash
To have something like:
ctroupin@gher13 ~/ULg/DIVA/Diva_python_tools (ReadPlotModule) $
add the following lines to your ~/.bash_profile
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
Source: https://coderwall.com/p/fasnya/add-git-branch-name-to-bash-prompt (but probably also described in the reference book).
Auto-completion
https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks Download from https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
Basic commands
General
The git reference book is extremely well written so most of the issues one might have can be solved by reading the book. However it is often easier to type the issue in a google search bar and find the solution in specialized forums.
GitHub
GitHub is an online project hosting using Git. GHER has now an account on GitHub to store the code and software: https://github.com/gher-ulg You need to [https://help.github.com/articles/signing-up-for-a-new-github-account/ create an account in GitHub] in order to be able to contribute to existing codes or to upload yours before the gher-ulg administrator can add you as a member of the organization.
Once that is done, if your code is uploaded in a repository within https://github.com/gher-ulg/, the other members of the organization can directly edit the code.
Coupling
Some repositories are also preserved using zenodo. This means that every time you create a release (it has to be done through the GitHub webpage, not with the command line), a publication and a DOI will be generated in zenodo (see image below). That release of the code can then be obtained from zenodo and cited properly.
Troubleshooting & FAQ
Move the most recent commits to a new branch
You have performed some changes in the master branch but then decide that these changes should have been inside a new branch:
git branch newbranch
git reset --hard hashnumber
git checkout newbranch
where hashnumber is the abbreviated commit hash (see Viewing the Commit history). Source: http://stackoverflow.com/questions/1628563/move-the-most-recent-commits-to-a-new-branch-with-git
Modify a file name
git mv old_name new_name
Source: https://git-scm.com/docs/git-mv
Changing a remote's URL
You decide that your code should be pushed to another repository or account: https://help.github.com/articles/changing-a-remote-s-url/ Use the command:
git remote set-url
Moving files to another repository with history conserved
Well described here: http://stackoverflow.com/questions/1365541/how-to-move-files-from-one-git-repo-to-another-not-a-clone-preserving-history
error: failed to push some refs to
git fetch origin
# Fetches updates made to an online repository
git merge origin YOUR_BRANCH_NAME
# Merges updates made online with your local work
Source: https://help.github.com/articles/dealing-with-non-fast-forward-errors/
Moving a code from SVN to Git
Documentation
- Follow the instructions from https://git-scm.com/book/en/v2/Git-and-Other-Systems-Migrating-to-Git.
- Using a recent version of git might help avoid some errors: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git.
- If you messed up with the author names: https://help.github.com/articles/changing-author-info/.
Comparison with SVN
Subversion vs. Git: Myths and Facts: list differences between the 2 VCSs. As the title says, there are some ''myths'' (and ''hype'') about the tools!
Workflow for Diva development
Small fixes
When correcting typos, editing README
etc: use the master
branch.
Bug fixes
Create specific branch that will be merged, then deleted.