How to Upload Django Project to Github.

Git is a version control system that lets you go back to any version of your code, even if you delete something important by accident. It also lets you keep track of all your work through commits and work with other developers. In this post, I’ll show you how to upload a Django project to Github.

Steps to upload Django project to Github:

  1. Install and setup Git (One-off)
  2. Create a Github account (One-off)
  3. git init!
  4. Optional: git status.
  5. Make A Commit.
  6. Create A New Github Repository.
  7. Push To Github Repo.

The first two stages are one-offs, which means you only have to do them once. Therefore the number of steps required to upload a Django project to Github is only five. These are git init, git status, git -A, git commit -m "message", create Github repository, and push to the Github repository.

So let’s get started:

Table of Contents

Step 1: Install and Setup Git (One-off):

Git allows us to run the commands that let us upload a Django project to Github, so it is crucial to have it installed in your operating system. I’ll explain some of the best and popular methods for installing Git for each major operating system namely Mac, Linux and Windows.

How To Install Git On Mac.

If you’re on Mac, type the following in your terminal:

$ brew install git

This works because homebrew comes preinstalled in most Mac computers, however if somehow you do not have it in your Mac, computer, you have to install it first. Head over to Git-scm’s Donwload for MacOS to learn more ways to install Git in your mac computer.

How To Install Git On Linux.

Type in the following command in the terminal of your Linux computer.

$ apt-get install git

Git-scm’s Download for Linux and Unix page offers more ways to download Git for other Linux distrubitions.

How To Install Git On Windows.

For Windows, it is a bit different, the best method to install Git is to use a Git installer.

Here is how to do it:

  1. Go to Git scm’s Downloads for Windows.
  2. Click on the Standalone Installer suitable for your Windows OS.
  3. After the download, run the installer by double-clicking it.
  4. Follow the setup wizard till the end of the installation.

You can also use the winget tool if you have it installed by running the following command:

$ winget install --id Git.Git -e --source winget

To learn more about installing the winget tool on Windows, check out its guide on Using the winget tool to install and manage applications.

Git Setup.

Check if Git has been installed correctly simply by checking its version.

$ git --version

Which should return you with the version of Git installed on your computer.

Now let’s set up Git.

Open your terminal and run the following commands one by one.

$ git config --global user.name "Your Name"
$ git config --global user.email "Your email Address"

The first command sets the name that is going to be used for other Git operations we will do. So does your email.

If you wish to change either of these credentials, just rerun the corresponding command with the new credential.

We are do Installing and setting up Git on our computer, it is time to create a Github account if you haven’t created one.

Step 2: Create a Github account (One-off).

Follow the steps below to create a Github command:

  1. Go to Github’s homepage.
  2. Click the ‘SignUp’ button.
  3. Enter your Email, Username, and Password.
  4. Verify the Human Test.
  5. Click the Create Account button.
  6. Verify your Email.
  7. Answer a few polls.

And we are In!

Step 3: Git Init!

Assuming that you already have the Django project created and are ready to deploy it to Github, cd into the project’s folder (that contains manage.py) Run the following command to initialize the folder as a local Git repository.

$ git init

Step 4 : Optional: Git Status.

The following command is used to check the status of your local git repository, if you run this command on a new Django project that has not been committed to git, it should return something like below.

$ git status

You are recommended to run this command to check if there are any changes to your Django code that need to be pushed to git, if there is any, this command will also give you a better idea of how you should name the commit as it lists out the current changes.

After checking the status, it is time to add the code to a commit.

Step 5: Make A Commit.

Now that the folder is a local git repository, you have to update it.

Run the following commands in that same terminal:

$  git add -A
$ git commit -m "initial commit"

The -A flag is for all, and the -m flag for message. The first commits you add to a repository are usually called ‘initial commit'(s). The next time you run the next command again in that same folder (git commit -m “message”) you have to change the message to cater for the most recent changes you made to the code.

Step 6: Create A New Github Repository.

  1. Click the ‘+’ dropdown at the top right corner of your Github dashboard and click on the ‘New Repository’ option.
  2. Type the name of the Repository. It is best practice to give it the same name as that of your Django project.
  3. Give a description of the project if you wish to do so.
  4. Choose if it is going to be a Private or Public directory.
  5. The next step ‘Initialize your project with:’ is optional, skip it if you wish to.
  6. Click the ‘Create Reposity’ button.

Step 7: Push To Github Repo.

For now, what we have done is initiated a folder in our computer to work as a local repository and then we created the actual Github repository which we want the code to be uploaded to. On the page that Github redirects you to after the creation of a new repository, we will use the second option that says ‘…or push an existing repository from the command line.’ This is because we have already created the repository through Github itself. We could have used the first option if that was not the case.

The code we are going to use looks something like this.

$ git remote add origin https://github.com/username/repository-name.git
$ git branch -M main
$ git push -u origin main

Conclusion: How to upload Django project to Github.

That was how to upload a Django project to Github. As you can see the first 2 steps are one-offs meaning you only have to do them once. The next steps you have to repeat every time you are uploading a Django project to Github. This leaves us with only 5 steps to upload a Django project to Gihub. Which are git init, git status, git -A, git commit -m "message", Github repository creation, and Github repository push. All Done

How to Upload Django Project to Github.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top