I have only basic knowledge in git.
I only cloned single branch from my remote using command line and following command (the repository has multiple branches at the time of cloning)
git clone <url> --branch <branch> --single-branch
I am able to do all git operations using my android-studio IDE vcs support to the cloned branch. Now I want to switch my remote branch but my android-studio IDE not showing the remote branches. It is showing only one branch that i used to clone. From the searches I had I checked the following solutions but doesn't work.
Refresh remote Git branches in Android studio
How can I get the list of remote branches without cloning the master branch from the scratch?
You are only seeing one branch, because you used --single-branch
From the git documentation:
--[no-]single-branch
Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is created.
To undo this:
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
To add a single branch:
git remote set-branches --add origin [remote-branch]
git fetch origin [remote-branch]:[local-branch]
Related
I've set up a Git server on my LAN (Simple Git Server for Mac). I'm using other machines on the LAN for Android Studio development. What now? On Android Studio's VCS menu, "Integrate Project..." is grayed out.
If I understand, I have to first create a local repository on the workstations, then somehow get my project files into it and get it copied to the server. Can't figure out how to do either. It seems usable if you already have your remote repository set up and populated, but I can't get to square one.
Also: is it recommended to have a separate repository for each project?
If you already have a git repository set up online. First you do git init in the directory that you want to submit to git, then you need to commit the files you want to add by doing git add . for all your files or git add <your file> for a specific file. After that you need to commit the files by doing git commit -m "your message here " and then you do:
git remote add origin <remote repository URL> //get this from git assuming your have already set up the git repo
# Sets the new remote
git remote -v
# Verifies the new remote URL
Push the changes in your local repository to GitHub.
git push -u origin master
# Pushes the changes in your local repository up to the remote repository you specified as the origin
All this info comes from the git documentation here:
https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
And yes, typically you want to have a separate repository for each project. There are exceptions, but personally, I have yet to find a suitable one.
I have downloaded the current master of Android AOSP which is Android 6.0 source code.
Is there a way available using repo to set the master to Android 5.1 so that all git repositories are set accordingly?
Note: I wish to do this without downloading again.
Quoting from source.android.com:
To check out a branch other than "master", specify it with -b. For a
list of branches, see Source Code Tags and Builds.
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
Edit
Note: I wish to do this without downloading again.
You can try with:
repo init -b <manifest-branch>
repo sync -j8
Edit 2
I want to know if there is way to do it without downloading. The sync
would download from google servers.
The documentation is really clear about the sync command:
Downloads new changes and updates the working files in your local
environment. If you run repo sync without any arguments, it will
synchronize the files for all the projects.
When you run repo sync, this is what happens:
If the project has never been synchronized, then repo sync is equivalent to git clone. All branches in the remote repository are
copied to the local project directory.
If the project has already been synchronized once, then repo sync is equivalent to:
git remote update
git rebase origin/<BRANCH>
where is the currently checked-out branch in the local
project directory. If the local branch is not tracking a branch in the
remote repository, then no synchronization will occur for the project.
If the git rebase operation results in merge conflicts, you will need to use the normal Git commands (for example, git rebase
--continue) to resolve the conflicts.
Since you already synchronized the project once the sync command is equivalent to a rebase.
I cloned a repo from Github. It was an eclipse Android project. I then imported it into Android Studio and have now got it up and running. I ran "git init" and am now trying to create a branch to work off of.
when I run git branch I get nothing. Terminal returns nothing and just goes to the next line. i have tried running git branch -a and git branch --list and still am getting nothing. There is no master branch showing or any branch for that matter.
I ran git checkout -b and it said the branch was created. But when I run git branch I still get nothing returned. I then tried to run git checkout master and received:
git checkout master
error: pathspec 'master' did not match any file(s) known to git.
I am not sure why this is happening and think it has something to do with the weird initial setup. (clone repo, then import into android studio, then run git init)
git init is for initializing a new git repository. Since you cloned from an existing repository on Github, there is no need to initialize a new one.
In general, if you git init to initialize a new repo, and then immediately invoke git branch without making any commits or creating any branches, then the behavior you experienced is expected: git branch will return nothing. Only after your initial commit (or you explicitly create a branch) will you see any branches listed.
In particular if you ran your git init and git clone in the same directory where you ran git clone to begin with, then you will not see any branches. If you change directory into the subdirectory that was created when you cloned, then git branch will probably list master for you (and git remote show origin will show you the remote branches).
I downloaded the android code from source.android.com. Then I created a new branch from this code:
repo start mybranch platform/external/webkit
Then I tried to switch to the new branch using :
git checkout mybranch
which failed with this error message:
fatal: Not a git repository (or any parent up to mount parent /media)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not
set).
I tried the steps mentioned in the android link.
One more problem: when I use the command
repo branch
it shows only the branch which I created eailer. How can I switch between the code I have downloaded and the code I have made changes to?
The android source consists of several hundred git repositories. The repo tool helps maintain all these repositories.
Therefore when you are directly in the root of your android clone, you are not actually in a git repository. You have to enter a sub-directory containing a git repository before you can start using git commands.
For example the build/ directory is a git repository itself, you can try:
$ cd build/
$ git checkout mybranch
Which sub-directory you need to enter of cause depends on where you want to modify the android source. :)
What happens behind the scenes when I do a repo sync in my Android repository?
Is it equivalent to repo forall -c "git pull" or maybe git fetch? Or does it do something more complex?
Thanks
There's a description on this page of what repo sync does. In the usual case it will be more like git pull --rebase than git pull. To quote what that page says:
How Repo synchronization works
When you run repo sync, this is what happens:
If the project has never been synchronized, then repo sync is equivalent to git clone. All branches in the remote repository are copied to the local project directory.
If the project has already been synchronized once, then repo sync is equivalent to:
git remote update
git rebase origin/branch
where branch is the currently checked-out branch in the local project directory. If the local branch is not tracking a branch in the remote repository, then no synchronization will occur for the project.
If the git rebase operation results in merge conflicts, you will need to use the normal Git commands (for example, git rebase --continue) to resolve the conflicts.
The repo sync command also updates the private repositories in the .repo/ directory.
Essentially the git remote update makes sure that your remote-tracking branches (including origin/branch) are up-to-date by running git fetch origin. (In fact, the behaviour of git remote update is more complex than that, and depends on your git config, but in a typical setup it'll run git fetch [remotename] for each of your remotes.) Then the git rebase origin/branch rewrites your branch by replaying all your commits that aren't present upstream onto origin/branch.