2026-03-13 (3VO): Git (SSH), C++ Intro ====================================== .. topic:: Trainer's note * Ensure that we access the repo over HTTPS *and see a password prompt* .. contents:: :local: Basic ``git`` Workflow: ``add``, ``commit``, ``push`` (, ``pull``) ------------------------------------------------------------------ * View changes Current working directory *somewhere inside* the tree, .. code-block:: console $ git status ... * ``git add`` changes: stage for next commit .. code-block:: console $ git add file.h file.cpp ... Review repo situation .. code-block:: console $ git status ... * ``git commit`` what you staged Either non-interactive (giving the commit message as a commandline parameter) .. code-block:: console $ git commit -m 'frobozz the foobar' Or letting git pop up your favorite ``$EDITOR`` .. code-block:: console $ git commit * ``git push`` * ``git pull`` SSH, And Using It For Git Repository Access ------------------------------------------- .. topic:: See also * :doc:`/trainings/material/soup/linux/ssh/basics` * :doc:`/trainings/material/soup/linux/ssh/key-pair` * :doc:`/trainings/material/soup/linux/ssh/scp` * :doc:`/trainings/material/soup/linux/ssh/portforwarding` * :doc:`/trainings/material/soup/linux/ssh/sshfs` From :doc:`/trainings/material/soup/linux/ssh/index`: * :doc:`/trainings/material/soup/linux/ssh/basics` * :doc:`/trainings/material/soup/linux/ssh/key-pair` Exercise: Key Pair, Deployed To Codeberg ---------------------------------------- * Create key pair. *Leave passphrase empty* (else you'll have to type it in over and over, just like the HTTPS password) * Send to trainer * Public key (``id_rsa.pub``) * Codeberg account name * Deploy SSH public key on Codeberg (account (icon above right) -> "Settings" -> "SSH / GPG keys") * You have a clone of your fork of the upstream repo; change that clone's upstream URL from HTTPS to SSH. First, look: .. code-block:: console $ git remote origin $ git remote -v origin https://codeberg.org/_codebergaccountname_/FH-STECE2024.git (fetch) origin https://codeberg.org/_codebergaccountname_/FH-STECE2024.git (push) Then set: .. code-block:: console $ git remote set-url origin ssh://git@codeberg.org/_codebergaccountname_/FH-STECE2024.git .. _fh-ss-2024-update-fork: Distributed ``git``: Update Your Fork From *Upstream* ----------------------------------------------------- .. figure:: forgejo-fresh-fork-and-clone.jpg :scale: 100% :align: left Current situation .. figure:: forgejo-update-fork.jpg :scale: 100% :align: left Wanted: merge changes from upstream * Create a remote for *upstream* https://codeberg.org/jfasch/FH-STECE2024.git .. code-block:: console $ git remote add upstream https://codeberg.org/jfasch/FH-STECE2024.git .. code-block:: console $ git remote -v origin https://codeberg.org/_codebergaccountname_/FH-STECE2024.git (fetch) origin https://codeberg.org/_codebergaccountname_/FH-STECE2024.git (push) upstream https://codeberg.org/jfasch/FH-STECE2024.git (fetch) upstream https://codeberg.org/jfasch/FH-STECE2024.git (push) * Fetch from *upstream* .. code-block:: console $ git fetch upstream ... roedel ... * Merge ``upstream/master`` into your local ``master`` branch Check that your current branch is ``master``, .. code-block:: console $ git branch * master Merge, .. code-block:: console $ git merge upstream/master Note that this is not always so easy - you might have to resolve conflicts. Push to default location - your fork, .. code-block:: console $ git push * Shorthand: ``git pull``. This is the same as ``fetch`` followed by ``merge``