Skip to content

Instantly share code, notes, and snippets.

@Elliria
Last active August 6, 2023 15:03
Show Gist options
  • Save Elliria/ede2d3951ee87bd095bcfa79b75d1e5e to your computer and use it in GitHub Desktop.
Save Elliria/ede2d3951ee87bd095bcfa79b75d1e5e to your computer and use it in GitHub Desktop.

Import a Project into GitHub

1. Prepare your computer for development

  1. Before you do anything else, make a backup of your local project!
  2. Check through all the folders in your local project and if any of them don't have any files in them, add a file to them. This matters when it comes time to push the changes to GitHub, because the push command won't send empty directories. A common practice is to put the empty .gitkeep file into empty directories.
  3. Grab all available operating-system updates.
  4. Update the apt database: sudo apt update
  5. Configure your git username in place of John Doe's: git config --global user.name "John"
  6. Configure your git user email in place of John Doe's: git config --global user.email "john.doe@example.com"
  7. (Optional) Configure your editor as nano instead of the default of vim: git config --global core.editor "nano"

2. Prepare GitHub for command-line access

  1. Create a personal access token on GitHub:
    1. Since GitHub no longer uses passwords for remote access from the command-line, you'll need to create a GitHub personal access token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token. Note that this will need to be repeated at the interval you specify, so keep the link handy.
  2. Configure GitHub's default branch name for new repositories:
    1. Go to your main GitHub profile.
    2. Click Settings in the context menu.
    3. Click Repositories in the left panel.
    4. Check if your Repository default branch name at the top of the right pane is master. If it's not, change it to master and click the Update button. Note that we're doing this because git uses master as the default branch and although you can change that, you have to jump through a lot of hoops to do so, so this is just easier.
    5. Click your GitHub profile picture in the top right corner.
    6. Click Your profile in the context menu.

3. Create a new GitHub repository

  1. Go to your main GitHub profile.
  2. Click Repositories in the menu.
  3. Click the New button.
  4. Type a repository name into Repository name text box.
  5. Optionally type a description into the Description text box.
  6. Choose whether to make it a public or private repository.
  7. Do not put a check-mark in the Add a README file box.
  8. Leave the Add .gitignore setting as is unless you're familiar with it and have a preference.
  9. Choose a license.
  10. Click the Create repository button to create the repository and open its main page. Note that you'll see several instructions, including a blue box with some quick setup information in it. That's exactly where you should be. Leave the browser open while you go on to the next section.

4. Create a local repository

  1. Open your local project's main directory in a terminal window on your computer.
  2. Initialize git in that folder: git init
  3. Check the status with the git status command, which will give you a message letting you know you are on the master branch and giving you some additional information.
  4. Add all of your project files with the git add . command.
  5. Check the status with the git status command to see which files were added.
  6. Commit the change with a meaningful comment noting that this is the initial import of your project: git commit -m "Initial import of project."

5. Share your changes with GitHub

  1. Go back to your GitHub repository's main page and copy the first line you see that starts with git remote add origin and ends with the URL to your GitHub repository.
  2. Go back to your terminal window and paste that line in to let git know where you'll want your changes to go.
  3. Push your changes to your GitHub repository with the git push -u origin master command.
  4. Type in your username at the prompt.
  5. Type in your personal access token at the password prompt.

6. Enjoy your remote repository on GitHub

Refresh your GitHub repository's main page to see that your project files have been added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment