DEV Community

Cover image for How to add your new project to GitHub in 10 easy steps
Sanjana Bhat
Sanjana Bhat

Posted on

How to add your new project to GitHub in 10 easy steps

Okay, I am fairly new to GitHub. And initially, I used to struggle a lot with adding my local projects to GitHub.
I created a cheat sheet, so here it goes.


0. Pre-requisites:

Git on your local machine
Here is a neat article to help with that.

1. Create new repository on github.

Do not initialize .gitignore or readme at this point.

2. In your project root folder, create a .gitignore file.

In this file, add all the folder and the file extensions that you wouldn't want in the remote repository.
The following is an example .gitignore for a java project.

*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

#folders
logs/
target/

#other
*.classpath
*.project
*.settings
*.pdf
Enter fullscreen mode Exit fullscreen mode
3. Initialize local repo

In your local, navigate to the project folder from your favorite command prompt
git init -b main

4. Add all files from your project to your local

git add .

5. See the status of changes in local

git status

6. Commit to local

git commit -m "commit message"
On a side note, it's a great practice to keep committing to your local in small increments. That way, if you see that a code change is breaking and don't know which line did that, it's easy to revert back to a stable version.

7. Specify the remote repo for current local repo

git remote add origin https://github.com/username/repo

8. Add files from local to remote

git push origin main

9. Add a README.md file in github repo.
10. In case you want to update local from remote

git pull origin main

That's it, you did it :)

Top comments (0)