Cant push new project to bitbucket from Android studio? - android

I created a new project in Android Studio. But I can not push it to bitbucket (I fight with it for all day, nothing works).
I get this error:
Push to origin/master was rejected
error: failed to push some refs to 'https://aaa#bitbucket.org/bbb/ccc.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
! refs/heads/master:refs/heads/master [rejected] (fetch first)
hint: (e.g., 'git pull ...') before pushing again.
Done
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
And this is what I do:
Android Studio (AS) -> New project
AS -> VCS -> Enable Version Control integration -> Git
AS -> VCS -> Git -> Remotes -> I added URL of repository I created in bitbucket
AS -> Right click on project => Git => Commit & Push - > ERROR
What is the problem? I dont understand the error message, I do not have any "another repository", it is just me working on this project, and it is newly created.
When I try to follow advice to PULL changes, it also does not work (I get another error). And when I try to google that one, I get another one and another one and I soon I get lost...its very complicated.
What am I doing wrong? All I want is just to push a new project to bitbucket...

Ok, I solved it. I have no idea why git kept giving me those random errors (when both repo and project were fresh and just minutes old, those error messages ddint make much sense), but this is what helped:
git push -f --set-upstream origin master
I guess it is just another proof how complicated, and unintuitive git is.

Related

how to fix Commit to git failed due to network

I added files to git git->add in android studio, files were added successfully. When I pressed commit and push, it was interrupted due to network issue. And nothing was pushed to git.
Now When I'm trying to add and commit, it ways nothing to push.
Kindly advise how to fix this in android studio.
Thanks in advance.
Your files already committed in your local system. Thats why you are unable to see any files when committing again.
To push the committed code, Goto VCS -> Git -> Push, You will see all the committed files, So you can push it to repository.
Alternative Terminal way,
You can also execute this command in terminal to push your code to master
git push -u origin master
Hope this helps.

How to do push code to a second and separate GitHub repository in Android Studio?

I'm stumped.
My project has it's original GitHub repository.
I will have to push the Android project to a second repository.
How to do push code to a second and separate GitHub repository in Android Studio?
I see hints that it's possible, but I don't know how to initiate to new repository.
Regards,
You can do so by either editing or adding remote URL from terminal.
To add:
git remote add origin2 https://github.com/user/repo.git
To edit:
git remote set-url origin https://github.com/user/repo.git
Then you can push to another remote repository.
In Android studio, you can press Ctrl+Shift+K and choose where to push the commits.
Follow these steps:
Go to the android project directory and open terminal then.
1.git init
2.git remote add bitbucket https://github.com/xxx/yyy.git (bitbucket is name i have given. you can use anything like origin2 etc.)
3.git add .
4.git commit -m "first commit"
5.git push -f bitbucket master

How to configure Android studio with gerrit commit and push

We have been using gerrit as our android source code repo. We usually use git bash
commands to do push ,pull and commit for working with gerrit.I want to how we can configure the android studio itself with gerrit so that i don't need to type in commands in git bash. I tried to change some settings in the Android studio in git version control option but that really didn't work.
One more thing is that whenever we do a commit through git commit command git creates (or something else i am sure as i am not very good at git commands and env) changeId: This is very important for pushing/amending the changes.How can i add changeId while i commit from studio.
Let me know if i am not very clear about my question , i will add more.
This is the image of my push Ui from studio where i can't see the origin HEAD :
Android Studio’s Git GUI should be able to do almost all the jobs through menus and buttons. The only annoying thing may be that you need to change the remote ref in the push menu from master or refs/heads/master to refs/for/master to create changes for review.
Change-Id is created by a hook commit-msg. As I know, it is under repo/hooks if you use Google’s REPO. The repositories cloned by repo sync have commit-msg deployed, so you don’t need to worry about it. But as for those repositories created by git clone or git init, you need to install it. Gerrit’s project page provides a clone command which includes scp that downloads and copies the hook automatically. If you clone through Android Studio, you could manually install it under .git/hooks/ for one repository, or copy it to $GITBASH/ming64(32)/share/git-core/template/hooks on Windows so that any new created repository will have it installed automatically.

How to discard local changes in Android Studio GUI?

I want to discard the local changes I made in an Android Studio project.
I tried to perform a pull, the GUI gives me 5 options, which option should I choose?
Octopus
Ours
Subtree
Recursive
Resolve
In Android Studio do the following:
-Open the Version Control tool window Alt+9 and switch to the Log tab.
-Select the recent commit and right click on it than select Reset Current Branch to Here.
-A Git Reset popup will open -> select Hard -> click Reset
You originally asked which strategy argument to use with git pull to discard your own work (there is a pending edit that will change the question, if the edit is approved). The answer is: None.
Don't use git pull at all. Run git fetch first:
git fetch origin
This brings over all the new stuff from the other Git you have your Git calling "origin".
Now that you have everything they have, simply stop using what you have been using, and switch to theirs:
git reset --hard origin/master # assuming you're on your "master"
You may also want to use git clean -fdx to remove build artifacts, but that's a separate issue.
In Android studio do the following:
Go to VCS -> Git -> Reset HEAD
Change Reset type to hard

Contribute on GitHub using Android Studio

I'm not new to using GitHub on Android Studio, but:
This is my first try to contribute to a sample project for Android on GitHub.
I did the following
I cloned the repository:
I made my changes
I committed my changes
I pushed my commit
And baam (here is the problem):
Why? What things did I miss?
(Don't forget, I have never contributed on GitHub, and this is my first time.)
403 indicates that you are not allowed to access the resource - you aren't authenticated with GitHub. To fix this, you should change your remote URL to a repository you have access to, then push your changes:
https://myusername#github.com/user/repo.git
From the command line you would need to do the following (Android Studio should automatically detect the changes):
git remote remove origin
git remote add origin https://myusername#github.com/user/repo.git
git push -u origin --all // prompts for authentication, pushes your changes to github
Your question has nothing to do with Android Studio, I guess if you try to push your changes through command line you'll get the same result. Read about Contributing to Open Source on GitHub.
First of all, to do a contribution:
You must fork the repository
Clone your fork version of that repository
Through the command line, navigate to your clone directory then add upstream version (original repository):
$ git remote add upstream https://github.com/fcannizzaro/material-stepper.git
You can check it using the line $ git remote, and you will see origin and upstream.
Make changes → commit them → then push (all of this happen on your repository (forked one), not the upstream).
Go and check the network graph for both the forked and original repositories.
Go to the GitHub original repository's link and click pull request.
Do as described in this image:
And fill the others field and click Create pull request
Thanks for Erik Carlsten's tutorials.

Categories

Resources