• Shopping Cart Shopping Cart
    0Shopping Cart
London App Developer
  • Courses
  • Consulting
  • Tutorials
  • About
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu
Android studio and Github software logos on a bright pink background image
Android, Android Studio

How to push to a remote Git repository over SSH with private/public key authentication using Android Studio

Android Studio is currently in Beta phase. However given that it is most likely to supercede Eclipse as the next Android IDE, I thought it would be a good idea to start using it now to develop my apps.

Like many software engineers, I use Git as my source control software. I have a set of Git repositories that I keep on a Digital Ocean cloud virtual machine. This serves as a central place to store my code as well as a backup in-case my hard disk fails or someone comes and steals my computer (knock on wood).

When I first started using Android Studio, it took me some time to figure out how to work from  a remote Git repository over SSH using private/public key authentication. As a result, I wrote this guide on how to do it.

At the time of writing this guide, I am using the following on my development machine:

  • Windows 8
  • Android Studio (Beta) 0.8.2
  • Git 1.9.0

How to push to a remote git repository in Android Studio

Open explorer, browse to c:\users\[your username]\ and create a directory called .ssh (if I doesn’t already exist).

Windows Explorer .ssh Directory
Windows Explorer .ssh Directory

This is where Android Studio will look for the configuration of your remote servers when you try and push/pull your repository.

Next create a new file inside your newly created .ssh folder and name it config.

Open the file with a text editor (I use Notepad++) and add the following:

Host [server url]
     HostName     [server url]
     Port         22
     IdentifyFile [location of your open ssh private key]

The contents of this file is as follows:

  • Host – this is the name of your host. This can be anything but I think it’s best to use the fully qualified domain name of your remote server.
  • HostName – this is the FQDN of your host (in my case its always the same as the host).
  • Port – this is your port which your ssh deamon accepts connection on. The default is 22.
  • IdentityFile – this is the path of your private key in open SSH format. This is important if you use private/public key as its the only way Android Studio knows which key to use to authenticate you.

Now load up Android Studio and create or open a project.

Once you have a project open, navigate to VCS (from the top menu) > Import into Version Control > Create Git Repository.

Selecting 'Create Git Repository in Android Studio'
Selecting ‘Create Git Repository in Android Studio’

On the Select directory for git init screen, choose where to initialize your local git repository (I usually leave the default select which is in the project directory) and click OK.

Selecting Git repository location in Android Studio
Selecting Git repository location in Android Studio

Next, navigate to the projects location in explorer, right click the background and select Git Bash

Location of project files in Windows Explorer
Location of project files in Windows Explorer

The git bash prompt will appear.

Git Bash in Windows
Git Bash in Windows

Add a new git remote by typing:

git remote add origin ssh://[user]@[server_address]/[git_repo_url]

This will create a git remote named origin. Each part is broken down below:

  • The [user] should be replaced by a user on the server that has read and write access to the git repo.
  • The [server_address] is the FQDN of the server hosting your git repo.
  • The [git_repo_url] is the location of the git repo on the server.

An example of the command could be ssh://mark@londonappdeveloper.com/usr/repo/my_android_project.git.

Now add a file to the git repository by typing:

git add .gitignore

I do this is because we need to add any file to our git repo to make our first commit (and this is created automatically by Android Studio when you initialize the git repo). After this, we will add the rest of the files using the Android Studio interface.

Now commit the changes to the git repository using the comment “Initial Commit”:

git commit -m "Initial Commit"

Next, push to the remote using the flag –set-upstream to tell git that the destination repository will be the upstream one.

git push --set-upstream origin master

The output will look something like this:

Git bash commands complete
Git bash commands complete

Press enter and then close the box.

In Android Studio right click your projects name(in the top left corner), then select Git and choose Add.

Adding all project files to git in Android Studio.
Adding all project files to git in Android Studio

This will add all the files from the root of the project to your Git repository (the same as when we typing git add previously).

Next, right click the projects name again, select Git and choose Commit Directory.

Commit Directory option in Android Studio.
Commit Directory option in Android Studio.

In the Commit Changes screen, confirm all your project files are selected by default, type a commit message and click Commit.

Selecting location for Git repository in Commit Changes screen
Selecting location for Git repository in Commit Changes screen

Next right click your project’s root directory (top left corner), and navigate to Git > Repository > Push.

Selecting Git push in Android Studio
Selecting Git push in Android Studio

The Git Push screen will appear. This will display the last commit that you are about to push. Click the Push button to send your changes to the remote git repository.

Git push screen in Android Studio.
Git push screen in Android Studio.

If all goes well, you should see this screen success message:

Message for a successful push in Android Studio.
Message for a successful push in Android Studio.

And that’s it. Every time you make changes you commit and push the updates to the remote Git repository.

As always, please leave comments below if you have any questions or ideas on how to improve this article.

Cheers,
Mark

Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://i0.wp.com/londonappdeveloper.com/wp-content/uploads/2014/08/How-to-push-to-a-remote-Git-repository-over-SSH-with-privatepublic-key-authentication-using-Android-Studio.png?fit=277%2C223&ssl=1 223 277 mark https://londonappdeveloper.com/wp-content/uploads/2018/12/lon_website_logo-300x110.png mark2014-08-04 07:58:212022-01-12 11:03:59How to push to a remote Git repository over SSH with private/public key authentication using Android Studio
6 replies
  1. Alexander
    Alexander says:
    December 17, 2015 at 7:17 am

    Thank you very much for such helpful note.

  2. karthikeyan
    karthikeyan says:
    April 1, 2016 at 3:37 pm

    I have following error when pushing a fie
    remote: error: insufficient permission for adding an object to repository databa se objects remote: fatal: failed to write object error: unpack failed: unpack-objects abnormal exit

    Please help me to solve this

    • mark
      mark says:
      April 1, 2016 at 4:49 pm

      Can you send a screenshot of the error?

      • karthikeyan
        karthikeyan says:
        April 2, 2016 at 5:33 am

        Thanks for your response mark.

        Here I have attached the dropbox link of the screenshot.

        https://www.dropbox.com/s/6jv84ln3yqrlprx/Error1.PNG?dl=0

        Please help me to solve.

        • mark
          mark says:
          April 2, 2016 at 8:11 am

          Did you try this? http://stackoverflow.com/questions/6448242/git-push-error-insufficient-permission-for-adding-an-object-to-repository-datab

          • karthikeyan
            karthikeyan says:
            April 3, 2016 at 6:44 pm

            Thanks mark. I will check.

Comments are closed.

Pages

  • About
  • Consulting
  • Home
  • Tutorials

Categories

  • AI
  • Android
  • Android Studio
  • Angular
  • Aptana Studio
  • AWS
  • Bootstrap
  • Career advice
  • Celery
  • Databases
  • Deployment
  • DevOps
  • Django
  • Django REST Framework
  • Docker
  • Eclipse
  • Getting Help
  • Git
  • Git Bash
  • Git Flow
  • GitHub Actions
  • Google App Engine
  • IDE
  • Ionic Framework
  • iOS
  • JavaScript
  • Job Search
  • Links
  • Linux
  • Mac OS X
  • macOS
  • Node.JS
  • OpenAI
  • PGAdmin
  • Postgres
  • Productivity
  • Python
  • React
  • Salt Stack
  • Stack Overflow
  • Tools
  • Travis-CI
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Vagrant
  • VSCode
  • WebSockets
  • Windows 10
  • WordPress

London App Developer Ltd,

71-75 Shelton Street, Covent Garden, London, United Kingdom, WC2H 9JQ

Company registration number: 09718346

© London App Developer - London App Developer Ltd, Company Registration Number: 09718346, VAT: GB224061842
  • Link to X
  • Link to Youtube
  • Link to Facebook
  • Link to Reddit
Link to: What to do if Aptana Studio 3 stops allowing you to commit to git? Link to: What to do if Aptana Studio 3 stops allowing you to commit to git? What to do if Aptana Studio 3 stops allowing you to commit to git?Aptana Studio and Git logos Link to: How to use GitHub with Android Studio Link to: How to use GitHub with Android Studio Github and Android Studio software logos on a yellow background imageHow to use GitHub with Android Studio
Scroll to top Scroll to top Scroll to top

This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.

OKLearn more

Cookie and Privacy Settings



How we use cookies

We may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.

Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.

Essential Website Cookies

These cookies are strictly necessary to provide you with services available through our website and to use some of its features.

Because these cookies are strictly necessary to deliver the website, refusing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.

We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.

We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.

Google Analytics Cookies

These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.

If you do not want that we track your visit to our site you can disable tracking in your browser here:

Other external services

We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.

Google Webfont Settings:

Google Map Settings:

Google reCaptcha Settings:

Vimeo and Youtube video embeds:

Other cookies

The following cookies are also needed - You can choose if you want to allow them:

Privacy Policy

You can read about our cookies and privacy settings in detail on our Privacy Policy Page.

Privacy Policy
Accept settingsHide notification only