Difference between revisions of "Getting Started w/ Github"

From AstroBaki
Jump to navigationJump to search
 
(12 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
== Introduction ==
 
== Introduction ==
 
+
[[Revision Control]]
  
 
== Creating a Github Repository ==
 
== Creating a Github Repository ==
Line 6: Line 6:
 
* [https://www.youtube.com/watch?v=rd-WiB_2oVQ Introduction to Git]
 
* [https://www.youtube.com/watch?v=rd-WiB_2oVQ Introduction to Git]
 
* [https://www.youtube.com/watch?v=SwK2dPFXhpU How to Install and Configure Git and Repositories on GitHub]
 
* [https://www.youtube.com/watch?v=SwK2dPFXhpU How to Install and Configure Git and Repositories on GitHub]
 +
* [https://docs.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line Adding an Existing Project to GitHub Using the Command Line]
  
If you don't have a github account that's where you'll need to start. You can get started setting up your account by going to [https://github.com/ github.com] and log-in using an email. Github has special benefits for students so if possible, use your school email.
+
If you don't have a GitHub account that's where you'll want to start. You can get started setting up your account by going to [https://github.com/ github.com] and log-in using an email. Github has special benefits for students, so if possible, use your school email. Once you've set up an account, in the terminal type the following commands:
 
 
 
<source lang="bash">
 
<source lang="bash">
git help {command}
+
git config --global user.name "John Doe"
 +
git config --global user.email johndoe@example.com
 
</source>
 
</source>
 +
These commands configure your command line to use your GitHub username and email from now and this should be the only time you have to type these commands.
  
== Adding Code/Data ==
+
== Creating a Repository ==
 +
One of the main benefits of Git and GitHub is the ability to synchronize files between different working environments (like your personal computer and a remote computer). Here, we'll set up a git repository and connect that repository to GitHub in order to synchronize files between different sources. Start by moving into the directory that you would like to use as your repository. Next, run the following command to create a git repository:
 
<source lang="bash">
 
<source lang="bash">
git config --global user.name "John Doe"
+
git init
git config --global user.email johndoe@example.com
 
 
</source>
 
</source>
 
+
Once you've initialized your repository, add files by using:
 
 
 
<source lang="bash">
 
<source lang="bash">
 
git add {file}
 
git add {file}
Line 27: Line 28:
 
git add .
 
git add .
 
</source>
 
</source>
 +
Once you've added the files that you work like to add to GitHub, you will need to commit those files. You can do this by running the command,
 +
<source lang="bash">
 +
git commit -m "Your Commit Message"
 +
</source>
 +
The commit message is used to remind yourself and others what you changed when you made that commit. The message should be less than 50 characters but descriptive enough to remind you of what changes were made. Now that files have been added, we need to connect this repository to GitHub. To do this, you'll need to start by logging into GitHub and setting up a repository on GitHub to store your file using the following [https://github.com/new link]. Give your repository a name and create the repository. Now, we'll need to link the repository on your computer to the repository you just created on GitHub. We can do this using the command:
 +
<source lang="bash">
 +
git remote add origin https://github.com/<your-username>/<your-repo-name>
 +
</source>
 +
Finally, run the following commands to add your committed files from your computer to GitHub:
 +
<source lang="bash">
 +
git branch -M main
 +
git push -u origin main
 +
</source>
 +
Once, these commands are run you should be able to see your files on GitHub. If you'd like to add this repository to another computer, log into the terminal of that computer and run the following command:
 +
<source lang="bash">
 +
git clone https://github.com/<your-username>/<your-repo-name>
 +
</source>
 +
This will copy files stored in your repository on GitHub to the computer that you're currently working on and will initialize a new repository on that computer. You can now add files and make and commit changes from this repository.

Latest revision as of 14:15, 13 January 2022

Introduction[edit]

Revision Control

Creating a Github Repository[edit]

Links:

If you don't have a GitHub account that's where you'll want to start. You can get started setting up your account by going to github.com and log-in using an email. Github has special benefits for students, so if possible, use your school email. Once you've set up an account, in the terminal type the following commands:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

These commands configure your command line to use your GitHub username and email from now and this should be the only time you have to type these commands.

Creating a Repository[edit]

One of the main benefits of Git and GitHub is the ability to synchronize files between different working environments (like your personal computer and a remote computer). Here, we'll set up a git repository and connect that repository to GitHub in order to synchronize files between different sources. Start by moving into the directory that you would like to use as your repository. Next, run the following command to create a git repository:

git init

Once you've initialized your repository, add files by using:

git add {file}

or if you want to add all of the files in a directory you can use the following command:

git add .

Once you've added the files that you work like to add to GitHub, you will need to commit those files. You can do this by running the command,

git commit -m "Your Commit Message"

The commit message is used to remind yourself and others what you changed when you made that commit. The message should be less than 50 characters but descriptive enough to remind you of what changes were made. Now that files have been added, we need to connect this repository to GitHub. To do this, you'll need to start by logging into GitHub and setting up a repository on GitHub to store your file using the following link. Give your repository a name and create the repository. Now, we'll need to link the repository on your computer to the repository you just created on GitHub. We can do this using the command:

git remote add origin https://github.com/<your-username>/<your-repo-name>

Finally, run the following commands to add your committed files from your computer to GitHub:

git branch -M main
git push -u origin main

Once, these commands are run you should be able to see your files on GitHub. If you'd like to add this repository to another computer, log into the terminal of that computer and run the following command:

git clone https://github.com/<your-username>/<your-repo-name>

This will copy files stored in your repository on GitHub to the computer that you're currently working on and will initialize a new repository on that computer. You can now add files and make and commit changes from this repository.