DEV Community

loading...

How To Upload Personal Projects to GitHub Using Only 6 Exact Git Commands Every Time?

Mohmed Ishak
I'm Mohmed Ishak, a software engineer and I love to write short and concise tech articles when I'm free.
・3 min read

Alt Text

You've heard of Git and GitHub but have you used them? If no, this article contains everything you need to know on how to upload your personal projects to GitHub. The good thing is, you only need to know these 6 commands.

Prerequisites:

Git, the actual version control tool should be installed on your machine. Link: https://git-scm.com/downloads Next, create a GitHub account, which is the code hosting platform. Link: https://github.com/

Step 1:

You need to understand that you're not supposed to commit all files to GitHub. So, you need to ignore unnecessary files. For example, in React projects, you can totally ignore "node_modules" folder which contains all the files you installed as dependencies because it is super heavy and unnecessary. The reason is that all the dependencies are specified in "package.json" file which means that when you or someone else download that project in future, you can reinstall all the dependencies locally on your machine without polluting GitHub. To ignore unnecessary files and folders, create a file named ".gitignore" in the root of your project. In the context of React application, you can include "node_modules" inside that file. Of course, there is more to this (such as hiding API keys and sensitive information), but for starters ignoring "node_modules" is pretty sufficient. Every stack has its own .gitignore template which you can always Google. Here's an example of ".gitignore" file for a Java project created using IntelliJ IDEA.

#
# Project specific excludes
#

tomcat

#
# Default excludes
#

# Binaries
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.war
*.ear
*.sar
*.class

# Maven 
target/

# IntelliJ project files 
*.iml
*.iws
*.ipr
.idea/

# OS
.DS_Store

# Misc
*.swp
release.properties
pom.xml.releaseBackup
pom.xml.tag
Enter fullscreen mode Exit fullscreen mode
Step 2:

Run a terminal window in your project folder.

Step 3:

Initialize a repository (empty folder).
git init

Step 4:

Add your files to staging area (a queue where your files "chill" before you decide to actually push it to GitHub).
git add .

Step 5:

Now, commit the files to your local repository. Write a meaningful message in quotation marks. Then, put the terminal aside (don't close it) and open your browser.
git commit -m "This is my initial commit."

Step 6:

Go to GitHub and create a new repository. Be sure to make confidential codes private such as company's projects. Otherwise, you'll regret it.
Alt Text

Step 7:

You'll see a couple of ways to upload your project to GitHub. I'll show you the second way, which is the easiest one in step 8.
Alt Text

Step 8:

Remember the terminal that you left aside? Paste the first line from GitHub under "…or push an existing repository from the command line".
git remote add origin https://github.com/yourgithubusername/REPOSITORYNAME.git
// write them in one line

Step 9:

More Ctrl + C && Ctrl + V
git branch -M main

Step 10:

git push -u origin main

Done!

Now, you know how to upload personal projects to GitHub using Git. This is sufficient if all you want to do is host your codes to GitHub, but collaborating with others and doing other cool stuffs require you to know a little bit more about Git and GitHub, which shouldn't be difficult to learn.

Discussion (0)