quick reference for git

updates to an existing repository

  1. Check the active username and e-mail address
    git config user.name
    git config user.email
  2. Check the local repository status.
    git status
  3. Compare files as needed.
    git diff filename
  4. Add any new and modified files for the next commit.
    git add -A
  5. Amend the commit message to describe changes and commit them.
    git commit -m "commit message"
  6. Push the commit to the remote origin (amend branch name if needed).
    git push -u origin main
  7. Confirm the latest commit in the log.
    git log

configuring a new repository

  1. Create the new repository specifying only the repository name and owner.
    • For Codeberg pages, set the repository name to "pages" (without quotes)
    • Make sure any settings to initialize the repository with a readme, license or .gitIgnore file are disabled, otherwise files will be created that will conflict with the local working/staging directory
    • Check that the default branch setting (in the advanced settings) is set to "main" (without quotes)
  2. Check the active username and e-mail address
    git config user.name
    git config user.email
  3. From the working/staging directory, initialise the local repository.
    git init
  4. [Only if needed] If the default branch setting could not be set to "main" (without quotes), perform a "checkout" to set it now.
    git checkout -b main
    (Warning: If there are files in a connected remote repository, the "checkout" command will overwrite files in the local working/staging directory with the current version of those files from the remote repository.)
  5. Make sure any necessary .gitIgnore file is applied to the working/staging folder now.
  6. Check the local repository status.
    git status
    This should report "No commits yet" and "Nothing added to commit but untracked files present".
  7. Add any new and modified files for the next commit.
    git add -A
  8. Amend the commit message to describe changes and commit them.
    git commit -m "commit message"
  9. Add the remote origin (only needed the first time, amend url as needed).
    git remote add origin https://codeberg.org/username/pages.git
  10. Push the commit to the remote origin (amend branch name if needed).
    git push -u origin main
  11. Confirm the commit in the log.
    git log

To remove and reapply a remote origin (in case the remote origin has been recreated since the local repository was last pushed, amend url as needed):
git remote remove origin
git remote add origin https://codeberg.org/ashraya/pages.git


user settings

check

git config -l

Look for user.name, user.email, and github.user.

change

set:
git config --global user.name "your username"
git config --global user.email "yourname@emailprovider.com"

Remove global to apply the change only to the current repository.

delete:
git config --global --unset user.name
git config --global --unset user.email

sometimes needed:
git config --global credential.username "your username"
git config --global credential.email "yourname@emailprovider.com"


deleting commits from a remote repository

This will also delete the changes in the local working directory! Ensure there is a copy elsewhere of all files that need to be retained.

  1. Reset to an earlier commit, deleting all subsequent commits
    git reset --hard last-good-version-SHA1-hash
  2. Force push the change
    git push origin HEAD --force