All git commands must be run after navigating to the repository folder. The only exception is git clone
, which creates the repository folder.
Unless you're a registered collaborator on gemlog, you need to log in to github and fork the gemlog repository before proceeding. Then, do the following steps:
- Run
git clone
to download the repository and set up the remotes if working with it for the first time, or rungit pull
to update it on your computer if you've worked on it before. - Create a new branch using
git checkout -b
- Edit the code. Run
git commit
every time you reach a stopping point. - After committing the last edits, run
git push
to write the changes to github - Create a pull request to have your changes merged into the primary repository.
If you are a registered collaborator on gemlog, you don't need to fork it, and you can push straight to the primary github repo.
Either way, your code should be on a named branch--please don't push code to 'main'.
git pull
git commit -a -m 'write a description of the commit changes here in quotes'
git push origin bug_fix
git branch -v
git checkout bug_fix
git checkout -b bug_fix
git stash
git checkout bug_fix
git stash apply
git add new_file.py
git clone https://github.com/ajakef/gemlog/
git remote -v
This is where you download updates from.
git remote add upstream https://github.com/ajakef/gemlog
This is where you upload your work to. If you don't have an ssh key created yet, you will need to make one with this command (changing the email address to the one you use for github: ssh-keygen -t ed25519 -C "[email protected]"
. Each time it prompts you for an answer, accept the default by pressing enter (unless you want it to do something else).
You then need to sign into GitHub and give it your public key so it knows to let you authenticate with your new ssh key. Click the account button in the top right, open Settings>SSH and GPG keys, click the "New SSH key" button, use the name of your computer as the "Title" and copy the contents of ~/.ssh/id_ed25519.pub into the "Key" window (without the email address at the end). Click the green button to finish the process.
If you're registered as a collaborator, you can push code directly to the primary repository (ajakef/gemlog). Otherwise, you can push code to your own gemlog fork on your own github site; in that case, just replace 'ajakef' below with your own github username.
git remote set-url origin [email protected]:ajakef/gemlog.git
You should now be able to push and pull from github just like before.
git status
git diff
Careful with this--there's no undoing it. This command must be run from the root folder of the repository.
git checkout .
git log
commit d875a48995b2f532b85b697463aa69dc12493d95 (HEAD -> main, tag: 1.3.6, origin/main, origin/HEAD)
Author: Jake Anderson <[email protected]>
Date: Tue Jan 12 15:56:04 2021 -0700
minor fix for inventory compliance with IRIS requirements
commit 8890ddeaa6b6e15af67ffacfe14e63da4fd56824
Author: Jake Anderson <[email protected]>
Date: Tue Jan 12 15:46:03 2021 -0700
minor fix to gem_network
commit cee5b2e1dd5890cc2240f4e595e0415be0f3ad4a
Author: Jake Anderson <[email protected]>
Date: Mon Jan 11 14:51:01 2021 -0700
minor changes to README.md and Installation.md
Temporarily check out an old commit (in this case, labeled cee5b2e1dd5890cc2240f4e595e0415be0f3ad4a)
It will tell you you're in "detached HEAD" state. This means that you can see the code in the commit you're checking out, and you can modify the code create a new commit based on it, but the new commit won't belong to any branch! You probably don't want that, so if you want to start creating new code based on an old commit, you should create a new branch here before committing anything.
git checkout cee5b2e1dd5890cc2240f4e595e0415be0f3ad4a
This assumes you were working on branch 'bug_fix'.
git checkout bug_fix
You can make a quick fix to the last commit if you found a small bug or if the commit message was wrong.
git commit -a --amend -m 'new commit message'
This won't delete the work you did, but it will remove the commit from the log. You will need to re-commit any changes you make.
git reset HEAD^
This makes it so you can use an ssh key to push and pull changes, rather than entering a username and password. First, follow instructions here to create a public/private key pair and then tell GitHub the public key.
git remote set-url origin [email protected]:ajakef/gemlog
If you have other remotes (e.g., your own fork, perhaps labeled "upstream"), you will need to repeat this process, replacing "origin" with the other remote's name.