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.
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/
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
Run a terminal window in your project folder.
Initialize a repository (empty folder).
Add your files to staging area (a queue where your files "chill" before you decide to actually push it to GitHub).
git add .
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."
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
More Ctrl + C && Ctrl + V
git branch -M main
git push -u origin main
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.