How to push an Android Studio project to Github via command line

Alessandro Lombardi
2 min readOct 10, 2021

--

When you create a new project on Android Studio, the IDE automatically adds a couple of .gitignore files:

Android Studio project tree

If we open these two files, we notice that they already include all the unnecessary file extensions and folders to track:

.gitignore auto generated by Android Studio

On GitHub, create a new repository. There is no need to initialize it with a .gitignore file, simply click the create repository button:

Github repo creation

Now, open a terminal (or the git bash app on Windows) at the root of the Android project, initialize git, add the desired files, and create the first commit:

git init
git add .
git commit -m "first commit"

Before we can actually push, we need to rename the current branch (master) to “main”:

git branch -M main

Add the URL of your repository:

git remote add origin http://github.com/Your-Username/Your-Repository-Name.git

Finally, we can push the project to Github:

git push -u origin main

Now you can find your project at the specified URL on the main branch.

--

--