Git Repository - General Guide


Recommended Posts

  • Community Leader

  • Member ID:  1
  • Group:  Community Leader
  • Followers:  10
  • Topic Count:  130
  • Topics Per Day:  0.05
  • Content Count:  393
  • Content Per Day:  0.14
  • Reputation:   32
  • Achievement Points:  3,705
  • Solved Content:  0
  • Days Won:  32
  • Joined:  07/11/2017
  • Status:  Offline
  • Last Seen:  
  • Device:  Android

GGU Git Repository - General Guide
This post is continuously being updated as methods/information changes, this can happen without any warning. Last update 1/22/25. Last Bot Update 1/22/25.

This is a comprehensive guide for those who don't mind reading a wall of text, this guide cover everything from Generating an SSH key, Adding an SSH key to your GGU Git Repository Account, Verifying an SSH key and other Git processes such as Initializing a repository, Adding Files, Pushing, Pulling, Committing, Creating/Removing Branches and Troubleshooting. If you have any question, please contact us on our Discord server under #helpdesk.

Generating a New SSH Key

You can generate a new SSH key on your local machine. After you generate the key, you can add the public key to your account on git.gguclan.com to enable authentication for Git operations over SSH. 

Windows:

Windows
  1. Install and open Git Bash (https://git-scm.com/downloads - Select Windows)
  2. Paste the text below, replacing the email used in the example with your GGU Git Repository email address. 
    ssh-keygen -t ed25519 -C "[email protected]"

    This creates a new SSH key, using the provided email as a label.
    When you're prompted to "Enter a file in which to save the key", you can press Enter to accept the default file location. Please note that if you created SSH keys previously, ssh-keygen may ask you to rewrite another key, in which case we recommend creating a custom-named SSH key. To do so, type the default file location and replace id_ALGORITHM with your custom key name (ssh_keyname). IF YOU ENTER A CUSTOM KEY NAME, CHECK "C:\Users\YOU\ssh_keyname". 

    > Enter file in which to save the key (/c/Users/YOU/.ssh/id_ALGORITHM or ssh_keyname):[Press enter]
  3. At the prompt, type a secure passphrase.
    > Enter passphrase (empty for no passphrase*): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]
    *Passphrase is required for the GGU Git Repository
  4. You should see this in the console if you did everything correctly:
    Your identification has been saved in ssh_keyname
    Your public key has been saved in ssh_keyname.pub
    The key fingerprint is:
    SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
    The key's randomart image is:
    +--[ED25519 256]--+
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    +----[SHA256]-----+

Adding your SSH key to the ssh-agent

Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key.

Windows:

Windows
  1. In a new admin elevated PowerShell window, ensure the ssh-agent is running. You can start it manually by using the command:
    Get-Service -Name ssh-agent | Set-Service -StartupType Manual
    Start-Service ssh-agent
  2. In a terminal window without elevated permissions, add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace ssh_keyname in the command with the name of your private key file (no file extension).
    ssh-add C:\Users\YOU\.ssh\ssh_keyname
  3. Add the SSH public key to your account on GGU Git Repository. For more information, see GGU Git Repository Account - Add a New SSH Key to your account.

Adding a new SSH key to your account

You can add an SSH key and use it for authentication, or commit signing, or both.

  1. Copy the SSH public key (.pub extension) to your clipboard 

    If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.
    Go to c/Users/YOU/.ssh/ or c/Users/YOU/ and locate the newly generated SSH key (ssh_keyname.pub) and copy the contents (Ctrl + C) - Make sure to open with notepad
  2. In the upper right-hand corner of the GGU Git Repository, click on your profile picture and go to Settings.
  3. Navigate using the left-hand menu to SSH / GPG Keys
  4. When on that page you'll see 2 options - Manage SSH keys and Manage GPG Keys. Select "Add Key" next to Manage SSH Keys.
  5. From there you'll need to enter a "Key Name", This can be anything that is easily identifiable in case you use multiple keys.
  6. Paste the information you copied from ssh_keyname.pub and paste under "Content" and click "Add Key". 

Verifying a newly added SSH key

Now we have to verify the SSH key that you just added before we can start using it. 

  1. Click "Verify"
  2. Follow the instructions given by the Git Repository for Linux or use the command below for Windows using Git Bash - Enter your passphrase when prompted. Replace token with the token provided by the Git Repository. 
    echo -n 'token' | ssh-keygen -Y sign -n gitea -f "C:\Users\YOU\.ssh\ssh_keyname" or "C:\Users\YOU\ssh_keyname"
  3. You should now see:
    -----BEGIN SSH SIGNATURE-----
    LOTS OF TEXT
    -----END SSH SIGNATURE-----
  4. Copy the SSH Signature and paste it into the Git Repository. 
  5. If the process was completed correctly, you should see "SSH key "SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" has been verified." and should show "Verified Key" above the key name you provided.

Creating/Initializing a Repository

Now that we our SSH key generated and added to our account, we can start getting to work.

  1. Create a new repository on the GGU Git Repository webpage by going under the organization (Development) and clicking "New Repository".
  2. Give the new Repository a name using underscores or dashes for spaces (Good repository names use short, memorable and unique keywords.) and set a Description.
  3. You should now see some instructions; from this point you'll want to create a directory for your repository on your computer "C:\Users\YOU\project_name" or anywhere of your choice.
  4. Now navigate to the repository path on your computer and right click in a blank area and select "Open Git Bash Here".
  5. When the Git Bash comes up, Enter:
    git init
    This will initialize the directory you've selected as a directory Git can use; you should see a .git folder be created if you have "View hidden folders" turned on as confirmation.
     
  6. Now enter
    git checkout -b main
  7. Enter
    git add README.md
    This will create a README file in the repository directory and add the file to the push que.
     
  8. Enter
    git commit -m "First Commit"
    This will tell Git that you are ready to commit the changes to the repository and the reason for the commit.
     
  9. Enter
    git remote add origin ssh://server_info_from_git_repo/organization_name(Development)/repository_name.git
    Check your repository for the full path under the SSH option.  HTTPS will not work properly and should not be used.
     
  10. Type in your passphrase when prompted - Note Git may ask if you want to trust ssh://server_info_from_git_repo/ with the server's footprint, type YES.
     
  11. Enter
    git push -u origin main
    
    Enter passphrase when prompted
    This will push the changes to the GGU Git Repository. 
     
  12. You can check the repository via the webpage to confirm the changes were made or you can use #dev-git-changes on discord.

General Git Commands

Now that we've created and initialized a Repository we can start running normal Git commands, these will vary for the projects you're working on - These are the general commands. If you can't figure out how to use a command, Git Bash does a pretty good job of explaining why something isn't working properly. 

Start a working area (see also: git help tutorial)

  • clone - Clone a repository into a new directory.
  • init - Create an empty Git repository or reinitialize an existing one.

Work on the current change (see also: git help everyday)

  • add - Add file contents to the index.
  • mv - Move or rename a file, a directory, or a symlink.
  • restore - Restore working tree files.
  • rm - Remove files from the working tree and from the index.

Examine the history and state (see also: git help revisions)

  • bisect - Use binary search to find the commit that introduced a bug.
  • diff - Show changes between commits, commit and working tree, etc.
  • grep - Print lines matching a pattern.
  • log - Show commit logs.
  • show - Show various types of objects.
  • status - Show the working tree status.

Grow, mark and tweak your common history

  • branch - List, create, or delete branches.
  • commit - Record changes to the repository.
  • merge - Join two or more development histories together.
  • rebase - Reapply commits on top of another base tip.
  • reset - Reset current HEAD to the specified state.
  • switch - Switch branches.
  • tag - Create, list, delete or verify a tag object signed with GPG.

Collaborate (see also: git help workflows)

  • fetch - Download objects and refs from another repository.
  • pull - Fetch from and integrate with another repository or a local branch.
  • push - Update remote refs along with associated objects.

Change git remote origin

  • remote -v - View current remote origin.
  • remote set-url origin <NEW_GIT_URL_HERE> - Change to a new remote origin.

Troubleshooting

These are general problems that you may encounter and how to solve them. 

  1. fatal: The current branch main has no upstream branch.
    To push the current branch and set the remote as upstream, use
    
        git push --set-upstream origin main
    
    To have this happen automatically for branches without a tracking
    upstream, see 'push.autoSetupRemote' in 'git help config'.

Alex%20Thunderhunter.gif

Link to comment
Share on other sites


  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.