ManageAllAdminScriptsWithGit: Difference between revisions

From T2B Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by 2 users not shown)
Line 71: Line 71:
<br>
<br>


=== working with branches ===
=== Working with Branches ===
If you want to work with branches, this is the workflow <br><br>
If you want to work with branches, this is the workflow <br><br>


Line 84: Line 84:
</pre>
</pre>
Notice the username! <br>
Notice the username! <br>
You can now work on your own fork. You can crated branches in the fork (see the previous section) <br>
You can now work on your own fork. You can create branches in the fork (see the previous section) <br>
<br>
<br>
If the remote master changes, you need to synchronize. You can see which forks are available to you:
If the remote master changes, you need to synchronize. You can see which forks are available to you:
Line 104: Line 104:
Fetch the upstream changes and synchronize with your own origin:
Fetch the upstream changes and synchronize with your own origin:
<pre>
<pre>
git fetch upstream
git pull upstream master
git merge upstream/master
</pre>
</pre>


All your changes can be pushed straight to your master since it is the fork:
All your changes can be pushed straight to your master since it is the fork:
</pre>
<pre>
git push origin master
git push origin master
</pre>
</pre>

Latest revision as of 13:59, 8 May 2019

  • The admin scripts are managed by Git
  • They should be mounted on all machines managed by quattor in /scripts


Git Workflow

Adding/Modifying the scripts from your computer

  1. Request an account from git admins
  2. add your ssh key to your profile
  3. Do an git clone git@git.iihe.ac.be:iihe-scripts.git to download the content of iihe-scripts locally
    If you already have the script directory locally, you can first make sure you are on the master branch with git checkout master , and then pull the possible updates with git pull
    If you have made some changes to the master branch (wich you shouldn't!!), use git stash to store the changes and get a vanilla master, and when on the new branch (next step) use git stash apply to apply the changes to the current branch.
  4. Make a new branch from master git checkout -b BranchImWorkingOn. The branch name should reflect what you plan on doing. Never use directly the master branch !!
    You can check this worked with git branch -ra that lists local & remote branches.
  5. Make your new scripts or modifications
  6. If you made new files/directories, prepare them for atomic commit: git add -N myfile
  7. Select the chunks of code you want to commit: git add -p , (explanations of letters here). Be as small and precise as possible for each commits.
  8. If you want to revert the adding chunks to the index you just did : git reset -p
  9. Do the commit for the chunks you selected git commit -m"short message" [-m"long message"]. The long message is optional.
  10. To list the last commits git log -<NumberOfCommits>
  11. Last, you need to push the local changes to the remote server : git push origin BranchImWorkingOn
  12. Make a merge request on the git site:

Summary Of Git Commands

# First
git clone git.blahblah
git checkout master
git pull -p # this updates the local branch taking origin
git checkout -b newbranch
#or git branch -m oldbranch newbranch

# if working on wrong branch
git stash
# then go to new branch
git stash apply

git branch -ra ==> lists repo & local branches

# Atomic commit (by hunks):
git add -N myfile #first prepare file before patchadding
git add -p
  y - indexer cette partie
  n - ne pas indexer cette partie
  a - indexer cette partie et toutes celles restantes dans ce fichier
  d - ne pas indexer cette partie ni aucune de celles restantes dans ce fichier
  g - sélectionner une partie à voir
  / - chercher une partie correspondant à la regexp donnée
  j - laisser cette partie non décidée, voir la prochaine partie non encore décidée
  J - laisser cette partie non décidée, voir la prochaine partie
  k - laisser cette partie non décidée, voir la partie non encore décidée précédente
  K - laisser cette partie non décidée, voir la partie précédente
  s - couper la partie courante en parties plus petites
  e - modifier manuellement la partie courante
  ? - afficher l'aide

  ==> this add hunks to index, needs git commit -m""
git reset -p   ==> revert the adding to index

git commit -m"" [-m"long message"]

git diff          ==> local / index
git diff HEAD     ==> local / repo
git diff --cached ==> index / repo

git log -3  ==> lists commit

# Pushing
git push origin newbranch   ==> pushes local branch to repo & creates new repo branch


Working with Branches

If you want to work with branches, this is the workflow

First, go to https://gitlab.iihe.ac.be. Go to the project you want to fork.
There is a little icon on the page that says 'fork'. Click on it it and follow the instructions.
You will then be taken to the web page of your clone. This is now the page that you need to clone.
Click the little icon with 'clone' to get the exact address.

Now, go to a terminal.

git clone git@gitlab.iihe.ac.be:Olivier/iihe-scripts.git

Notice the username!
You can now work on your own fork. You can create branches in the fork (see the previous section)

If the remote master changes, you need to synchronize. You can see which forks are available to you:

git remote -v
origin  git@gitlab.iihe.ac.be:Olivier/iihe-scripts.git (fetch)
origin  git@gitlab.iihe.ac.be:Olivier/iihe-scripts.git (push)

And add the upstream master:

git remote add upstream  git@gitlab.iihe.ac.be:iihe/iihe-scripts.git
git remote -v
origin  git@gitlab.iihe.ac.be:Olivier/iihe-scripts.git (fetch)
origin  git@gitlab.iihe.ac.be:Olivier/iihe-scripts.git (push)
upstream        git@gitlab.iihe.ac.be:iihe/iihe-scripts.git (fetch)
upstream        git@gitlab.iihe.ac.be:iihe/iihe-scripts.git (push)

Fetch the upstream changes and synchronize with your own origin:

git pull upstream master

All your changes can be pushed straight to your master since it is the fork:

git push origin master

Adding /scripts to a machine and getting access to it

  • You need to mount with nfs (or autofs) the /storage of tesla
  • Then create a symlink from /storage_mnt/storage/group/admin/iihe-scripts to /scripts
  • Or you can just include the template in config/nfs/storage in your machine, which does all this.
  • It is in read-only for non-root users of the admins group, so you cannot make any modifications there.
  • If you want access as non-root user, you need to add yourself in freeipa [accessible through tunnel only] to the admins group.

Clean local branches

  • removes local branches already commited
git branch --merged
for b in $(git branch --merged|grep -v master);do git branch -d $b;done 
  • removes remote branches already committed
git branch --no-merged
git branch -r
git remote prune origin  # removes remote branches already committed



Old Wiki page for using SVN