Git repository: Difference between revisions

From LHEP Wiki
Jump to navigation Jump to search
(Created page with "From the https://docs.github.com/en/get-started/start-your-journey/about-github-and-git official Github website: <blockquote> GitHub is a cloud-based platform where you can store, share, and work together with others to write code. Storing your code in a "repository" on GitHub allows you to: * Showcase or share your work. * Track and manage changes to your code over time. * Let others review your code, and make suggestions to improve it. * Collaborate on a shared...")
 
No edit summary
Line 23: Line 23:
<div style="font-weight:bold;line-height:1.6;">Automatically add your ssh key(s) to the ssh-agent </div>
<div style="font-weight:bold;line-height:1.6;">Automatically add your ssh key(s) to the ssh-agent </div>
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
<syntaxhighlight lang="bash">
<pre>
# Run the ssh-agent if not running yet
# Run the ssh-agent if not running yet


Line 94: Line 94:
ssh-add ~/.ssh/id_ed25519_your_ssh_key0 &>/dev/null
ssh-add ~/.ssh/id_ed25519_your_ssh_key0 &>/dev/null
ssh-add ~/.ssh/id_ed25519_your_ssh_key1 &>/dev/null
ssh-add ~/.ssh/id_ed25519_your_ssh_key1 &>/dev/null
</syntaxhighlight>
</pre>
</div></div>
</div></div>

Revision as of 22:11, 8 August 2025

From the [official Github website]:

GitHub is a cloud-based platform where you can store, share, and work together with others to write code.

Storing your code in a "repository" on GitHub allows you to:

  • Showcase or share your work.
  • Track and manage changes to your code over time.
  • Let others review your code, and make suggestions to improve it.
  • Collaborate on a shared project, without worrying that your changes will impact the work of your collaborators before you're ready to integrate them.
  • Collaborative working, one of GitHub’s fundamental features, is made possible by the open-source software, Git, upon which GitHub is built.

The LHEP Github is the place where the repos should be stored in order to be accessible throughout LHEP members. It is a very good practice to work from repos, as cited, this helps keeping track of your work and allow others to easily use it.

Getting access to LHEP Github

If you aren't a member yet, (once you have an account) contact an owner (e.g. [Serhan] or [Nicolas]) to get added. Then you will be able to create your repository or use an already existing one.

Cloning the repo on a local machine

The remote github acts as the main repository. You can clone this repository on local machine which allows you to work on it. Once your work done, you can push your work from your local to the remote repo, such that it is saved in the cloud and other people can access it. On the other way around, if somebody else pushed something from their local repo to the remote one, then you can pull the changes from the remote repo to your local one such that you can use the work from others.

To clone a repo, first you will have to 'link' your machine to the remote repo. An easy way to do this is to set up an ssh key, follow this tutorial, under generate a new ssh key. Note that if you want to clone many repo on the same machine, you will have to generate one key per repo. If you do not want to add your ssh key to your agent everytime you connect to your machine, you can add the following commands in the .bashrc or .bash_profile:

Automatically add your ssh key(s) to the ssh-agent
# Run the ssh-agent if not running yet

# Function to start a new agent and save its info
# from https://docs.vscentrum.be/accounts/ssh_agent.html
start-ssh-agent() {
#
# Start an ssh agent if none is running already.
# * First we try to connect to one via SSH_AUTH_SOCK
# * If that doesn't work out, we try via the file ssh-agent-environment
# * And if that doesn't work out either, we just start a fresh one and write
#   the information about it to ssh-agent-environment for future use.
#
# We don't really test for a correct value of SSH_AGENT_PID as the only
# consequence of not having it set seems to be that one cannot kill
# the ssh-agent with ssh-agent -k. But starting another one wouldn't
# help to clean up the old one anyway.
#
# Note: ssh-add return codes:
#   0 = success,
#   1 = specified command fails (e.g., no keys with ssh-add -l)
#   2 = unable to contact the authentication agent
#
sshfile=~/.ssh/ssh-agent-env
#
# First effort: Via SSH_AUTH_SOCK/SSH_AGENT_PID
#
if [ -n "$SSH_AUTH_SOCK" ]; then
  # SSH_AUTH_SOCK is defined, so try to connect to the authentication agent
  # it should point to. If it succeeds, reset newsshagent.
  ssh-add -l &>/dev/null
  if [[ $? != 2 ]]; then
    echo "SSH agent already running."
    unset sshfile
    return 0
  else
    echo "Could not contact the ssh-agent pointed at by SSH_AUTH_SOCK, trying more..."
  fi
fi
#
# Second effort: If we're still looking for an ssh-agent, try via $sshfile
#
if [ -e "$sshfile" ]; then
  # Load the environment given in $sshfile
  . $sshfile &>/dev/null
  # Try to contact the ssh-agent
  ssh-add -l &>/dev/null
  if [[ $? != 2 ]]; then
    echo "SSH agent already running; reconfigured the environment."
    unset sshfile
    return 0
  else
    echo "Could not contact the ssh-agent pointed at by $sshfile."
  fi
fi
#
# And if we haven't found a working one, start a new one...
#
#Create a new ssh-agent
echo "Creating new SSH agent."
ssh-agent -s > $sshfile && . $sshfile
unset sshfile
}

# Start the ssh-agent
start-ssh-agent 
#&>/dev/null

# Add the key
ssh-add ~/.ssh/id_ed25519_your_ssh_key0 &>/dev/null
ssh-add ~/.ssh/id_ed25519_your_ssh_key1 &>/dev/null