I am new to Android Studio. I am wondering if I could create different branches to run my application. Likewise for example, if there is any possibility to have same copy of application but the difference would be just that ,one would run the production app and the other branch would run the test app.
So please suggest some method if available, to create branches or tags in Android Studio.
For this I would recoment to use gitflow here is an explanation image from nvie.com.
You can find the details in the link above. In short you use it to maintain features independed. You work on the development branch and your stable version is the master branch. So you can add fixes for the stable version without getting issues while fixing bugs with committed changes.
Back to your question how to add a branch in Android Studio click on the lower right edge in Android Studio and create that branch you want to:
If you need more information write a comment.
Create an account on github.com or bitbucket.com
then create a new repository for your project
Please read this git doc:
https://git-scm.com/book/fr/v1/D%C3%A9marrage-rapide
it's in french but there is an english version here https://git-scm.com :
in command line init git for your project:
cd ~/project-path-here
git init
git add .
git commit -am "initial commit"
git remote add origin <your link>
git push -u origin master
then manage your project with git.
You can create a branch with
git branch -checkout <new_branch_name>
Then you should be merge into your develop, release then master branch. You can use this git flow nvie.com
Related
I have already did my first commit of my app on Github. Now I want to maintain several versions (like 1.0, 1.1, 1.2 etc.) of my app, whenever I add a new module to my app, on Github. How to do that using android-studio VCS or using terminal?
You can create different branchs for each version. You can have your current version in a generic especific branch and before you change to a new version, create a new branch named after the version of your choice.
If the current version is 1.2, for example, and you need to create a new version, stay in your current branch, create a new branch for version 1.2 and after that return to your current branch. (it will copy all the content of the current branch to a new branch).
To create a branch you can follow this example:
git checkout -b v1.2
When you go back to the current branch, your new changes will not affect your old version 1.2. It will be safe in it's own branch v1.2.
I would go with tags. That's the correct way to manage versions (or releases) of your app.
The Git Flow approach suggest you start from the master branch, then create a new branch called develop.
git checkout -b develop
From there you will create a new branch for each feature/request/issue and after it is done, return to the develop branch.
To create a new branch, if positioning in develop
git checkout -b new-feature
Commit as much as you want in that branch and when done, upload it to GitHub
git push -u origin new-feature
If the feature is done you can create a Pull Request in GitHub and merge that branch with the develop branch.
Repeat the process until you are ready for a new version/release.
Once you are done create a pull request in GitHub to merge develop into master.
Now the master branch will have all you want for you new version.
To tag it, position on master and update it from GitHub
git checkout master
git pull origin master
Now your local branch is up-to-date. Let's tag it
git tag v1.0
An you can also upload the tag to GitHub
git push --tags
A TAG is a mark in your repository pointing to the code of the specific version/release you have tagged.
THE SITUATION
I am a fresh android developer and I made an easy application that I want to publish. There are two versions: one free with limitations, and an other without limitations. 99.99 percent of the code is same in the two versions, so I would like to work with them simultaneously. I have already used GIT and version control before, but only to save my data. So the point is I have never used branches.
THE PROBLEM
Of course I would like to learn to use the stuff, but now I am looking for a quick solution how to edit both of them.
So I am standing on my last commit and I would like to make the branching, but I have no idea how.
Steps for git branching :
1) Creating branch :
git checkout -b <new-branch-name>
2) Checking your current branch :
git branch
3) Switching branches :
git checkout <branch-name>
in your case
git checkout FREE or git checkout PRO
4) Make commits on your checked out branch.
5) For pushing the code to particular branch :
git push origin <branch-name>
in your case
git push origin FREE or git push origin PRO
respectively.
Hope this helps.
In order to create a branch, just run git branch <branch-name>. That will create a new branch right on the revision where you are right now. Then you can check it out (git checkout <branch-name>) so you can commit on it (nothing will the touched on the original branch). Both steps can be achieved at the same time with a single call: git checkout -b <branch-name>.
Git can’t work with two versions simultaneously, but branches in git can make it separately. So you just need to work on two branches to develop your code based on different versions.
Assume the two versions are A and B, and they both located on your default branch master. The structure looks like:
A---B master
Now you just need to create a new branch from the other version A by
git checkout -b dev <commit id for A>
Then your branch structure will look like:
A---B master
\
… dev
Then you can make change and commit separately for this two branches. For one time you can just make/commit changes for a branch since there has the same working directory.
Such as when you are working on dev branch (HEAD point to it), you can just make/commit changes based on version A. Then you can switch HEAD to point master by git checkout master, then make changes and use git add . and git commit -m 'message' to commit changes.
Finally you can use git push origin branchname to push to remote.
I'm working on a project where we have reached a milestone. My git repository is up to date and everything is working correctly. Our client has now updated their api's and we're unsure how it will affect our code.
What I want to do is create a branch (already done) and upload the full repository to the branch. So I will have the project duplicated, one in the master and one in the new branch. I will then work and commit to the new branch leaving the master untouched. So going forward then for each release I can do the same, so we can fall back to the previous branch if there's any problem.
Can someone tell me how to do this please. I'm using Git and I'm working through a mac terminal.
I've gone through relevant questions on SO but I don't see the info I require, or perhaps I've missed it.
You don't upload a repository to a branch.
You have your code in a repository, and the repository has branches. No duplication, but you can get (checkout) master or the branch to set your working files to the version you want: master for untouched changes, branch for your recent changes.
Always good to do when you have reached a milestone is to tag the commit:
$ git tag v1.0
Then from there you can start a branch to work on integrating the new API
$ git checkout -b client_api_update
Work and commit in your branch. It does not affect the content in master, which you can checkout when you want to get your working files as they were in your milestone version (or checkout the tag).
When the integration of the new API is done, it's time to merge your branch to master in order to release support of the new API:
$ git checkout master
$ git merge client_api_update --no-ff
--no-ff is optional, but I think it makes for a more elegant history.
You are at a new milestone, so tag:
$ git tag v1.1
Here is how your history would look like:
/- v1.0 /- v1.1
A---B------------------G - master
\---C---D---E---F-/ - client_api_update
Let's say the branch you created in the main repo is <main_repo_new_branch>. Then the steps would be:
cd <local_repo_dir>
git remote add mainrepo <main_repo_dir>
git push mainrepo <local_repo_branch>:<main_repo_new_branch>
cd <main_repo_dir>
git checkout <main_repo_new_branch>
This question already has answers here:
How do you synchronise projects to GitHub with Android Studio?
(13 answers)
Closed 5 years ago.
I'm using Android Studio to code my apps. Now I want to work on 2 PC's and thought about using a Cloud-Service. I decided to use GitHub, but I can't find a way to synchronize my GitHub account with my Android Studio project...
Can anyone explain this to me ?
Best way to do this is probably through the good ol' command line. First, make sure you have git installed and in your path. You can get instructions from here.
Next, go to GitHub and create a new repository with a title and such. Instructions on that here. Don't worry about creating your first commit, we're going to do that on your local machine.
Now for the fun part.
Copy the repo link of your choice (I prefer ssh, but it depends on how far you went with the set up part) and head to the terminal.
cd ~/project-path-here
git init
git add .
git commit -am "initial commit"
git remote add origin <your link>
git push -u origin master
If all has gone well, you can reload the github page and see your new push.
On your other computer, you'll be able to clone down the repo you created.
cd ~/project-path-here
git clone <your link>
You can then use git pull and git push to retrieve and send changes to the server.
You can also look into Github's desktop application if you're on Windows or Mac for a simpler time, but I find these lack some more advanced features of git.
EDIT: To register your new git repo with Android Studio, Intellij, RubyMine, etc., go to the project settings (File->Settings), search for version control, and specify that your project is using git for version control. Here for more information on that. Once that is enabled, the VCS drop down will have more features. The ones to look at are Commit Changes (git commit and push) and Update Project (git pull).
Under the VCS tab in your Studio, there's on option to publish the project to Github. Will ask for your credentials, then you're good to go to push your code.
Just getting into Android app dev and I thought I might mention here that I think that we should gitignore the build folder. It's huge and it doesn't need to be repo'd
[Edit] I'm referring to the app/build folder. And hey I see it's not included in the Android Studio .gitignore
I have a whole android project code,it is very different from google's,because a team have developed on it for one year.Now I decide to use git instead of svn.And I want to use repo script to maintain the project.How to transfer?I've try to mirror a git server from Google via
repo init -u https://android.googlesource.com/mirror/manifest --mirror
then build my branch,but when I merge my project code to it,it is too difficult.
Is there a easy way?Thanks!
I am working on this same issue, the most progress I have made is due to this google group discussion.
From what I can tell you are going to have to maintain projects individually using git (I think you can do a repo start instead of git branch to setup your branches, then when you are ready to push changes you can use git push to the mirror. The thing you can gain from the repo script is the ability to use repo sync to sync all of the projects, and repo start to make new branches.
Could you be more specific about the problem you ran into with the merge? I may be able to help more on that front.