LibreNMS Git Workflow
- Git terms for this document.
Fork = A copy of the LibreNMS repository (repo).
We need to differentiate between the original LibreNMS and your fork of LibreNMS Git repo. All modifications and additions you make to LibreNMS will be sent to your Git repo. The Git commands on your server need to know which repo is the original and which repo is the fork. Unfortunately, the terminology used for Git repos is counter-intuitive. Your Git configuration doesn't have to set to 'Origin' and 'Upstream'. However, for the sake of clarity, and to conform to the Git docs, we will use these configuration settings.
Upstream = LibreNMS git repository.
Origin = Your fork of the LibreNMS git repository.
cd /opt
git clone https://github.com/<your-git-account>/librenms.git
Sample /opt/librenms/.git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/<your-git-account/librenms.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = librenms
merge = refs/heads/master
[remote "upstream"]
url = https://github.com/librenms/librenms.git
fetch = +refs/heads/*:refs/remotes/upstream/*
-
Basic setup, assumes git repo has been cloned to your account
-
OR if librenms.git has already been cloned, manually set origin
git remote add upstream https://github.com/librenms/librenms.git
- Setup Git
```bash cd /opt/librenms
git config branch.autosetupmerge true git config --global user.name "John Doe" git config --global user.email johndoe@example.com
Go to your git page and fork librenms, then tell git to add an origin, which is your RobsanInc fork of LibreNMS
git remote add origin https://github.com/RobsanInc/librenms.git
Show your remote gits
git remote -v
##Example output from 'git remote -v'
origin https://github.com/RobsanInc/librenms.git (fetch) origin https://github.com/RobsanInc/librenms.git (push) upstream https://github.com/librenms/librenms.git (fetch) upstream https://github.com/librenms/librenms.git (push)
Checkout and create '-b' a local branch
git checkout -b issue-1991
OR the above can be done in two steps
git branch issue-1991 git checkout issue-1991
Edit or create new files, then add these files to new branch
git add path/to/new/files/or/folders git commit -a -m 'Added feature to do X, Y and Z'
Push all of these files to origin (RobsanInc) git repo
git push origin --all
Then go to robsan github page and do a pull request for issue-1991
Clean-up after pull request has been accepted to librenms master
##Switch to local master, then delete local branch
git checkout master git branch -d issue-1991
##Delete remote origin (RobsanInc git) branch
git push origin --delete issue-1991
create an issue on github, or do it via the command line
Git reset local master to upstream (librenms git) and then push your recently reset master to the origin (robsan git)
git checkout master git reset --hard upstream/master git push origin master --force
GitHub Commands
- Clone a git repository, pulls all of the files to your local machine
git clone https://github.com/librenms/librenms.git
- Show the status of the remote git repository compared to the local git repository, must be run from the directory where the git clone was executed.
git status
- Tell git a new file or a modified 'index.html' exists and add it to the local repository, must be run from the local git directory.
git add index.html
- Add all changes in git directory.
git add -A
- Commit all changes and new files to the local repe, '-m' adds a message to describe the changes you made, must be run from the local git directory.
git commit -m "added new index.html"
- Push local repository changes to the remote (GitHub) reposistory, must be run from the local git directory
git push