Как залить проект android studio на github

от admin

GitHub Integration with Android Studio IDE

As developers, a lot of the time we tend to work on local development sites then just upload everything when we’re done. This is fine when it’s just you and the changes are small, but when you’re dealing with more than one person working on something, or on a large project with lots of complicated components, that’s simply not feasible. That’s when we turn to something called version control.

Today I’ll be talking about enabling an open source version control software called Git on Android studio and how to do integration with Github.

After joining Andela Learning Community (ALC 2.0) which is a program that connects people who have passion and enthusiasm for learning software development with beginner/ intermediate courses in Android/Web development powered by Google and Udacity. After few weeks in the program, it was a challenge to some of my colleagues to link Android studio IDE with Github that’s why I decide to write this post hope it will help someone.

Step 1: Test if Git executable path is correct

In Android Studio, go to File –> Settings –> Version Control –> Git. Then click Test to ensure that Git is configured properly in Android Studio.

Step 2: Login to your GitHub Account

Next, go to File –> Settings –> Version Control –> GitHub.
Add your GitHub credentials in login, you can either use the email you used to sing up for GitHub account or your GitHub username. And then click Test to ensure GitHub connection.

Step 3: Enable Version Control

We need to tell Android Studio to enable version control for the current project. We can do this by visiting the VCS option in the top menu, and selecting Enable Version Control Integration then choose Git,this will create a local Git repository in the project folder. After we set our VCS to Git, you’ll find that Android Studio will make us a .gitignore file by default.

Step 4: Playing around with Android Terminal

Once Git is set up, you should be able to do basics git command like git status/add/commit changes, as usual, using the Terminal located at the bottom of Android Studio IDE.

Git Status

We use git status, to keep monitoring the states of both the working directory and the repository.
when you do git status on the terminal you will be able to see we have untracked file (note the color is Red) and the branch of our Repo.

Git Add (Staging the changes)

let’s now stage our changes by the following commands

Changes have been staged (not the color changed from red to green). This means that git knows about the change, but it is not permanent in the repository. The next commit will include the changes staged. Should you decide not to commit the change, the status command will remind you that you can use the following command to unstage these changes.

Git Commit (Commiting the changes)

Let’s commit the staged changes to the repository. When you write a commit y include the -m flag that gives a comment on the command line.

Step 5: Share your project on Github

Once you’re ready to share your project on GitHub, Select the VCS menu option, then Import into Version Control and Share Project on Github.

Here, you can choose your GitHub repository’s name and description.Click Share to push the project to GitHub.

C ongratulation. Here is the sample repository created along with changes done in our first commit.

Note: there’s is terminal option if you would wish to use terminal

Thank you very much for your time if you have any feedback kindly write in the comment.

Дополнительные статьи

Github представляет популярный репозиторий проектов, который упрощает ведение командной работы над одним проектом, а также позволяет отслеживать все сделанные в нем изменения.

Для работы прежде всего необходимо создать учетную запись на сайте https://github.com. Также для работы необходимо установить инструментарий git, установщики которого для различных ОС можно найти на сайте https://git-scm.com/

Возьмем какой-нибудь проект. В Android Studio перейдем к пункту меню VCS -> Import into Version Control -> Share Project on Github .

Далее надо будет ввести логин и пароль от учетной записи на github.com:

Аутентификация Github и Android Studio

Затем будет предложено ввести дополнительный пароль (Master password):

Master password in Android Studio

Если подобного пароля не указывалось ранее, оставим это полу пустым и нажмем OK.

Далее будет предложено указать имя репозитория, удаленное имя и описание:

Настройки репозитория Github из Android Studio

Описание лучше писать на английском. После ввода всех данных нажмем на кнопку Share.

После этого будет предложено указать те файлы проекта, которые мы хотим закинуть на github:

Выбор файлов в Android Studio для экспорта на Github

После удачного экспорта файлов в Android Studio отобразится соответствующее сообщение.

Итак, наш проект уже расположен на github, однако впоследствии мы можем произвести в нем изменения, например, добавить файлы кода, изменить какой-то код. И в этом случае нам надо будет обновить проект в репозитории. Для этого перейдем к пункту меню VCS -> Commit Changes. :

Экспорт на Github из Android Studio

После этого отобразится окошко со сделанными изменениями со времени последнего коммита. В поле Commit Message укажем хаактер сделанных изменений. Для завершения обновления нажмем внизу окошка на кнопку Commit and Push. :

Обновление проекта на Github из Android Studio

Затем отобразиться дополнительное окошко, где надо подтвердить коммит. Для этого нажмем на кнопку Push :

How to add an Android Studio project to GitHub [duplicate]

I have a project in Android Studio. I want to add that project to a GitHub repository using android studio. How can I do that?

Tony Baby's user avatar

4 Answers 4

  1. Sign up and create a GitHub account in www.github.com.
  2. Download git from https://git-scm.com/downloads and install it in your system.
  3. Open the project in android studio and go to File -> Settings -> Version Control -> Git.
  4. Click on test button to test «path to Git executables». If successful message is shown everything is ok, else navigate to git.exe from where you installed git and test again.
  5. Go to File -> Settings -> Version Control -> GitHub. Enter your email and password used to create GitHub account and click on OK button.
  6. Then go to VCS -> Import into Version Control -> Share Project on GitHub. Enter Repository name, Description and click Share button.
  7. In the next window check all files inorder to add files for initial commit and click OK.
  8. Now the project will be uploaded to the GitHub repository and when uploading is finished we will get a message in android studio showing «Successfully shared project on GitHub». Click on the link provided in that message to go to GitHub repository.

Tony Baby's user avatar

You need to create the project on GitHub first. After that go to the project directory and run in terminal:

Oleg Khalidov's user avatar

If you are using the latest version of Android studio, then you don’t need to install additional software for Git other than GIT itself — https://git-scm.com/downloads

  1. Create an account on Github — https://github.com/join
  2. Install Git
  3. Open your working project in Android studio
  4. GoTo — File -> Settings -> Version Controll -> GitHub
  5. Enter Login and Password which you have created just on Git Account and click on test
  6. Once all credentials are true — it shows Success message Or Invalid Cred.
  7. Now click on VCS in android studio menu bar
  8. Select Import into Version Control -> Share Project on GitHub
  9. The popup dialog that will occur contains all your files with check mark, do ok or commit all
  10. At next time whenever you want to push your project just click on VCS — > Commit Changes -> Commit and Push.
Читать:
Как запретить пользователям менять ip

That’s it. You can find your project on your GitHub now.

ikmazameti's user avatar

First of all, create a Github account and project in Github. Go to the root folder and follow steps.

The most important thing we forgot here is ignoring the file. Every time we run Gradle or build it creates new files that are changeable from build to build and pc to pc. We do not want all the files from Android Studio to be added to Git. Files like generated code, binary files (executables) should not be added to Git (version control). So please use .gitignore file while uploading projects to Github. It also reduces the size of the project uploaded to the server.

  1. Go to root folder.
  2. git init

Create .gitignore txt file in root folder. Place these content in the file. (this step not required if the file is auto-generated)

*.iml .gradle /local.properties /.idea/workspace.xml /.idea/libraries .idea .DS_Store /build /captures .externalNativeBuild

Note : As per suggestion from different developers, they always suggest to use git from the command line. It is up to you.

How to use GitHub with Android Studio

Android Studio makes it easy to push changes to your favorite Open Source, professional, or personal projects on GitHub. In this tutorial, we’ll learn how to use GitHub with Android Studio. We’ll use an Open Source contribution for context.

Android developers use Open Source projects to speed up development or enable functionality that is otherwise impractical to build. Therefore it’s essential to understand how to give back and improve the Open Source projects that we use.

Requirements

  • A GitHub account installed

Selecting project

First of all, to which Open Source project should you contribute? You can contribute to any project, but, ideally, it’s one that you know and use.

What to contribute

Sometimes, during the usage of an Open Source library, we encounter bugs that we wish were fixed and missing features that we want added. When that happens, it’s tempting to request it to the maintainer(s) and hope for the best, or even search for another library. However, it’s essential first to consider contributing with that bug fix or feature we want. It’s often not as complicated as we may think.

Alternatively, we may want to contribute to the project in general and select a request that’s made by the community. In this case, the best way to find an idea is to look through the issues list and select an issue that seems simple enough for a first contribution.

Image shows the Stream Chat Android library issues list

For this tutorial, I’ll fix a bug that I encountered while testing the sample app. In this case, the sample app crashed when pressing an image inside the chat, instead of showing it in full screen.

Cloning the repository

With Android Studio, you don’t need to use the terminal to contribute to an Android project on GitHub. It has native integration with git and GitHub to allow most actions via the Android Studio UI.

When you open Android Studio, it offers the option to open a project from version control. That’s the option we’ll use.

Image shows Android Studio welcome screen with an arrow to the Get from Version Control button

After selecting that option, you can type the URL of the repository, press "Clone", and select a folder. After that, Android Studio will do all the work and open the project ready to go.

Image shows two Android Studio screens. One for typing the git repository URL and the other loading it as a project.

Making the change

Initially, the default branch will be selected, but often projects have a development branch that receives the changes before merging them to master. Let’s create a branch for our change based on that development branch. That is a better practice than using the development branch directly, to not risk polluting it.

Image shows Android Studio opened with an arrow pointing to the label where it says Git: default branch

To do that, click where it says "Git: [default branch]", select the development branch, click "New Branch from Selected", and choose a name for your branch.

Image shows dropdowns with the branches and a dropdown from development branch with "New branch from selected" option selected and a dialog to name the new branch

After that, we can proceed with making the change we want. After debugging the project, I’ve identified that initializing Facebook’s Fresco library in the MessageListView class solves the issue.

Image shows Android Studio with changes made to the MessageListView file to initialize the Fresco library

Now that we fixed the issue, we’re ready to commit it and send a Pull Request to the main GitHub repository. The next step will show how to fork the repository, in case you don’t have permission to push a branch to the main repository, which is often the case if you’re not a maintainer of that project.

Forking the repository

If you’re not a maintainer of that repository, you can’t push your branch to it. You’ll need to fork it first and push the branch to your fork. To do this, go to the GitHub repository and press fork.

Image shows a GitHub repository page with an arrow to the Fork button

You’ll need the URL of your repository in the next step, as we’ll push the branch to it.

Committing and pushing the change

Now, we can commit our change. To do this, either press CMD+K (or CTRL+K on Windows), or navigate to Commit via the menu.

Image shows the menu dropdown with the commit button

Review your changes in the screen provided, write a descriptive commit message, press the arrow on the "Commit" button, and select "Commit and push". That will take you to the screen where you’ll choose which repository the branch will be uploaded. If you’re a maintainer of the origin remote, you can press "Push" and skip to "Creating the pull request".

Image shows the screen to choose which repository to push to

If you’re not a maintainer, you should press the "origin" label, which will allow you to define a new remote repository. After that, you still need to select the proper remote and press the "Push" button.

Image shows the remote being switched and an arrow to the push button

If you’re not yet authenticated, Android Studio will ask for your GitHub credentials.

Image shows dialogs to authenticate with GitHub

After you authenticate, Android Studio will send the changes to your remote repository.

Creating the pull request

Now, go to your repository page on GitHub, and you’ll see a prompt to open a Pull Request with your newly pushed branch.

Image shows GitHub repo page with a prompt to open a Pull Request with newly pushed branch

When you press that, it will take you to a Pull Request composer. Generally, it will already contain a template that you can follow to describe your PR and some instructions that you need to follow. Also, don’t forget to check out the contribution guidelines of the project if it has one.

Image shows Pull Request being composed and the base branch being switched to develop

Usually, GitHub will pick the master branch as a base, so don’t forget to switch it to the development branch, if it exists, as the image shows.

Wrapping up

Congratulations! You just learned how to contribute to an Open Source project using GitHub and Android Studio, without having to touch the command-line interface. After you’ve sent your Pull Request, the project’s maintainers will review it and ask for changes if needed, in which case you can follow the "Committing and pushing the change" step again.

At Stream, we have many Open Source Android projects in Kotlin and Java, and we’re happy to receive and help you with your contributions.

Похожие статьи