First created in the cloud remote code repository, and then create a local project in Android Studio, these two steps are not described in detail.
- AndroidStudio following Terminal switch to the directory this project (if already, would not have switched), or right-Git Bash Here in the project directory, and then execute
git init
the command to initialize - Add all of the files in the project to the local repository cache them (if you want to add to a document, you keep in the back of this document can git add, if you add more than one file, multiple files with a space between intervals. Express Add all the files to the workspace cache)
- Submission
- Pushed to the remote repository
Tip: Some references will not be pushed to the remote repository, the update was rejected because the remote does not contain your local job done, first of all you want to change to a local integrated remote, for example:git pull
and then try to push again.
This problem occurs because the code I created a remote repository containing readme.md cloud and .gitignore files, create local projects have different .gitignore file and no readme.md files, remote file repository updates should first reach a local push again . git pull
Tip: The current branch is no tracking information. Please specify the branch to use.
If you want to set up tracking information for this branch, you can use the following command:git branch --set-upstream-to=origin/<branch> master
git branch --set-upstream-to=origin/master master
- Git pull again, suggesting refused to merge unrelated to history
the question is irrelevant because the two fundamental git repository, a local library, a distal library, go to the local then pushed to the distal end of the distal feel that with their local library irrelevant, so the merger can not be told.
There are two ways to solve:
The first method: Kula down from the remote codes that start with git clone remote repository to local, then copy the code to be added to the local library clone distal to the local library, and then submit up , because in that case, your library is based on a remote database, this is the first update.
The second method: using the force commandgit pull origin master --allow-unrelated-histories
, followed by --allow-unrelated-histories, to two unrelated branches merging force. And then push it back. git pull origin master --allow-unrelated-histories
We should resolve the conflict .gitignore file- After the file is to resolve the conflict, the conflict submitted to the cache file, as follows
- Then run the commit command, as
this time the local repository is the latest, and then execute git pull check, you do not need to update the local repository
- The last successful push to a remote repository, as follows: