Original link: https://www.cnblogs.com/imqsl/p/6763133.html
In the process of using studio to develop projects, sometimes we want to publish the project to github. In the past, we used a more troublesome way (cmd) to submit. Recently, we found that studio actually comes with this function, and we can finally get rid of it. command line too.
Because I haven't done in-depth research, here I will share the steps to upload my own project to github through studio.
Two related concepts: Git and github
Git is an open source distributed version control system for efficient and high-speed version management of projects ranging from very small to very large .Git is an open source version control software developed by Linus Torvalds to help manage Linux kernel development. The biggest difference between distributed and centralized is that developers can submit to the local, and each developer copies a complete Git repository on the local machine through git clone.
As an open source code repository and version control system, github is a website that provides git services to users. In this way, you can use the git services provided by them without having to deploy the git system yourself and register an account directly. GitHub hosts various git repositories and provides a web interface. GitHub's unique selling point is the ease of branching from another project. Contributing code to a project is very simple: first click the "fork" button on the project site, then check out the code and add the changes to the code base just forked, and finally be responsible to the project through the built-in "pull request" mechanism People apply for code merge.
Prepare
Install Androidstudio and create a new project;
Install git version control system. Such as Git GUI;
Sign up for an account on the github website.
step
1 Studio's git configuration;
After installing git, start Androidstudio and open the following path File->Settings->Version Control (expand)->git
Enter the git path you installed in the input box after Path to Git executable, as shown in the following figure:
Click the test button if the Git executed successfully dialog box appears, indicating that the configuration is successful, and the dialog box will display the version number of git you installed; as shown in the following figure
2 Configure github login information;
Open the following path File->Settings->Version Control (expand)->GitHub, as shown in the following figure
Fill in the following information:
Host:github.com
Login: your github account name
Password: your github account password
After filling in, click the test button. If the following dialog box appears, the configuration is successful. Note that the storage directory of the new version of git is D:\Program Files\Git\cmd
3 Upload the project to github
Open the project you want to upload, and select VCS->Import into Version Control->Share Project on GitHub from the top menu, as shown in the following figure:
If you are submitting the project for the first time, the following dialog box will appear, prompting you that this is a new repository (repo), you can customize the name of the repo and add a description.
After filling in, click the share button. If there is no problem with your project, the following interface will appear.
The classes to be submitted, as well as various resource configuration files, etc. are listed here, click the ok button
Note : This step is prone to upload failure. The reason is that it is not configured in git-bash:
Today, the blogger is happily learning to use Git in AndroidStudio, and the result is the following error ∑(っ°Д°;)っ:
Can't finish GitHub sharing process
Successfully created project 'Demo' on GitHub, but initial commit failed:
*** Please tell me who you are. Run Git config --global user.email "[email protected]" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: empty ident name (for (null)>) not allowed during executing git -c core.quotepath=false commit -m "Initial commit" --
看了一下错误原因:Run git config --global user.email "[email protected]" git config --global user.name "
原来是git没有配置的原因,找到git安装目录下的Git Bash运行后输入下面两行代码即可:
-
- git config --global user.email "[email protected]"
- git config --global user.name "Your Name"
问题解决接着继续:
输入你的Master password点击ok,如果提交成功studio右上角会提示相关信息
此时打开你的github网站地址在你的repositories中会看到刚刚提交过的工程名称,点击进去会看到完整的提交工程,到此提交结束
项目更新
当项目新增了模块或者模块修改了如何更新github上的项目,其实也很简单。
1 如果你的项目新增了一个类,当你创建该类的时候会提示你是否需要加入git,如下图所示
选择yes该类就会加入git,同时该类本身的颜色会有改变(Darcula主题下由正常的白色变为绿色)
此时该类右击->Git->COmmit File... 出现如下对话框
填写 commit message 后点击Commit按钮,有可能会出现如下警告,忽略它点击Commit
再次右击->Git->Repository->Push,如下图所示
点击Push出现如下对话框,点击Pust按钮
此时打开你的github上的该项目源码,你会发现新增的类已经出现了
2 如果你的项目中某个类进行了修改需要重新提交;
右击该类->Git-Add
感觉这步没什么变化?其实不是,这步其实是吧该类加入到git中;
以后的步骤和新增类的操作一样,这里不再赘述。
让我们先看看Git 跟 GitHub 是什么关系?
git是一个版本控制工具
Github是一个用git做版本控制的项目托管平台。
如果要想在AndroidStudio将项目发布到Github上, 第一步当然是安装Git(Git for windows 下载地址)。
在此之前,一定要拥有Github的账号。
安装Git
在windows安装Git很简单。只需要默认安装就可以。无需过多的配置。
需要教程的同学看这里 Windows下安装最新版Git配置AndroidStudio 中的Git
先创建一个Android测试项目
然后设置AndroidStudio
将git.exe路径配置好
将创建好的项目分享到Github 点击后去让你登陆Github 下图
登陆后 验证通过会跳出下个对话框
创建仓库 点击Share
点击OK这时候就可以把项目发布到GitHub上了 稍等一会 到GitHub 上看一下 是不是已经上传上来了呢?
接下来让我们创建个新文件
创建后 AndroidStudio会弹出下面对话框 这时候要点击Yes
在修改一下MainActivity ,作为测试用。
点击主面板上的 Commit Changes 按钮 并填写 提交信息 点击commit 。
继续点击commit
这时候 你会跑去GitHub上 看看有没有上传成功。 发现项目并没有改动
别着急,我们还需要一步操作
将项目push到 Github
点击Push 弹出下图后 在去网页端看看 ,是不是已经上传到Github上了
.gitignore
is here, the project has been published on Github, and it has learned to commit. At this point, you may have discovered that some documents do not need to be submitted to Github. Then use .gitignore
Come! Let's figure out which files should be submitted to GitHub for Android Studio projects?
#我用的是这份
#built application files
*.apk
*.ap_
# files for the dex VM *.dex # Java class files *.class # generated files bin/ gen/ # Local configuration file (sdk path, etc) local.properties # Windows thumbnail db Thumbs.db # OSX files .DS_Store # Eclipse project files .classpath .project # Android Studio .idea #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. .gradle build/ # Signing files .signing/ # User-specific configurations .idea/libraries/ .idea/workspace.xml .idea/tasks.xml .idea/.name .idea/compiler.xml .idea/copyright/profiles_settings.xml .idea/encodings.xml .idea/misc.xml .idea/modules.xml .idea/scopes/scope_settings.xml .idea/vcs.xml *.iml
The next time you submit, AndroidStudio will automatically ignore the files that do not need to be uploaded.
How to delete a GitHub repository
How to delete a Github repository? It's easy to
click setting