Working with GitHub: Difference between revisions
EricMiller (talk | contribs) (Created page with "GitHub is a way to keep track of your code for a project, while also allowing a team to work independently on the same project. It is a bit unintuitive to use; it combines using a web browser with command line functions (through the Mac terminal, or Windows Command Line). =Installing Git (one time only)= Macs: Install Xcode, which will include Git automatically <br> <code> xcode-select --install </code> Windows: https://git-scm.com/download/win To check to se...") |
EricMiller (talk | contribs) No edit summary |
||
Line 33: | Line 33: | ||
#* On your terminal: | #* On your terminal: | ||
#: <code> git clone <clone link> </code> | #: <code> git clone <clone link> </code> | ||
#* All of the code in the repository is now downloaded to your local computer, in a folder with the repository name. | |||
=Making changes to a repository= | |||
== Making changes to a file on your local computer, i.e. work on your code== | |||
* You should see a new directory named after the repository on your own computer. You can then edit this document in a text editor. I suggest Sublime Text (https://www.sublimetext.com). | |||
= | * You can test your code locally by: | ||
** Use the terminal to move to your repository folder | |||
<code> python <name of the file you want to run> </code> | |||
'''Please note: your file must be saved in the text editor before python 'sees' the changes!''' | |||
==Updating your code back to the repository on GitHub== | |||
* Use the terminal to move to your repository folder | |||
* Check the status of the repository | |||
** <code> git status </code> | |||
* Check the logs of the file (seeing what others have changed, for example) | |||
** <code> git log </code> | |||
** <code> git log -oneline </code> | |||
===Single files, destroying what was on GitHub=== | |||
This is best for if only one person is working on a project. It clobbers / overwrites the previous file, so it is not best if more than one person is working on the project. | |||
# Use the terminal to move to your repository folder | |||
# Add a file to the staging area | |||
#:<code> git add [file-name] </code> | |||
# Add all new and changed files to the staging area | |||
#:<code> git add -A </code> | |||
#:'''However, your changes are not permanent until you commit them. This uploads them back to the online repository''' | |||
# Commit changes | |||
<code> git commit -m "add a small description of the change" | |||
==Resetting and Reverting changes== | |||
* resetting a certain number of commits (after reviewing the log) | |||
** <code> git reset --soft HEAD~<number of commits to undo> <\code> | |||
** use <code>--soft</code> to uncommit and keep staged changes | |||
** use <code>--hard</code> instead to uncommit and delete changes | |||
<br> | |||
Each change in the log as a number/letter hash associated with it. To uncommit that change, copy this hash. | |||
* <code> git revert <commit hash> </code> |
Revision as of 11:40, 19 June 2024
GitHub is a way to keep track of your code for a project, while also allowing a team to work independently on the same project. It is a bit unintuitive to use; it combines using a web browser with command line functions (through the Mac terminal, or Windows Command Line).
Installing Git (one time only)
Macs:
Install Xcode, which will include Git automatically
xcode-select --install
Windows: https://git-scm.com/download/win
To check to see if the installation was successful, run:
git --version
Getting onto GitHub (one time only)
- Create an account on GitHub https://github.com/
- Create a SSH key for GitHub: (Do this on each computer that you own (not in a computer lab) will be using regularly)
- Notice that there is a tab to change the instructions to Windows or Linux.
- I recommend setting up a passphrase (a password) to secure your computer even more.
- Follow the "Generation a new SSH key" and the "Adding your SSH key to the ssh-agent" sections.
- Then, follow the "Adding a new SSH key to your GitHub account"
- Key type: Authentication Key
Cloning the repository (the first time you are working with a new project, i.e. a new code repository)
- If needed, ask Eric for access to the proper repository.
- Log onto GitHub and navigate to the repository that you are working on. For example:
- Clone the repository
- Click on the green "<> Code" button
- Select SSH
- Copy the resulting link
- On your terminal:
git clone <clone link>
- All of the code in the repository is now downloaded to your local computer, in a folder with the repository name.
Making changes to a repository
Making changes to a file on your local computer, i.e. work on your code
- You should see a new directory named after the repository on your own computer. You can then edit this document in a text editor. I suggest Sublime Text (https://www.sublimetext.com).
- You can test your code locally by:
- Use the terminal to move to your repository folder
python <name of the file you want to run>
Please note: your file must be saved in the text editor before python 'sees' the changes!
Updating your code back to the repository on GitHub
- Use the terminal to move to your repository folder
- Check the status of the repository
git status
- Check the logs of the file (seeing what others have changed, for example)
git log
git log -oneline
Single files, destroying what was on GitHub
This is best for if only one person is working on a project. It clobbers / overwrites the previous file, so it is not best if more than one person is working on the project.
- Use the terminal to move to your repository folder
- Add a file to the staging area
git add [file-name]
- Add all new and changed files to the staging area
git add -A
- However, your changes are not permanent until you commit them. This uploads them back to the online repository
- Commit changes
git commit -m "add a small description of the change"
Resetting and Reverting changes
- resetting a certain number of commits (after reviewing the log)
git reset --soft HEAD~<number of commits to undo> <\code>
- use
--soft
to uncommit and keep staged changes
- use
--hard
instead to uncommit and delete changes
Each change in the log as a number/letter hash associated with it. To uncommit that change, copy this hash.
git revert <commit hash>