Cannot see any git branches - android

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).

Related

How to run a specific version of the app from Git via Android Studio?

I use git as my VCS and commit my code every few days. However, a bug has crept in and I need to check if the previously committed versions of the app had that bug too.
How do I keep switching the current codebase to different git versions without losing the local changes that I have not committed? Is there a way in Android Studio to directly build and test a specific version from the git?
Some may suggest git stash and git stash pop/apply.
git stash
git checkout <commit>
# build and test
git checkout <previous-branch>
git stash pop
# or git stash apply
But I recommend git worktree. Suppose the version is abc123:
git worktree add /path/to/foo abc123
cd /path/to/foo
# build and test
The folders and files of abc123 are checked out into /path/to/foo. It does not affect the current main working tree. When the job is done in /path/to/foo, you can just remove the extra working tree by:
git worktree remove /path/to/foo
# or
rm -rf /path/to/foo
git worktree prune

Git could not see remote branches in android studio

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]

Why is GitHub causing me pain?

Ok I'm having this issue. I pushed (fresh repo) my Android app to my repo on Github from Android Studio. I then pulled it from AIDE on my tablet. I received no errors, even after pulling, from Android Studio. However, when I use AIDE I get errors such as invalid pack declaration (it's setup correctly). I change it to how it appears in the path, it works just fine (even tho in Android Studio my original setup was right). After that I get a bunch of errors saying R is an unknown entity. R.Java is present, so that's not it. I added the suggested import and that branches off to more errors.
Edit
The commands I have been using are as follows:
On initial setup:
cd C:\...path here
git init
git add .
git commit -m "First commit"
git remote add origin <urltorepo>
git remote -v
git push origin master
updating:
git add --all
git commit -m "message"
git push origin master
and this is what I've been getting:
warning: LF will be replaced by CRLF in <file>
The file will have its original line endings in your working directory
Fixed by recreating the repo and leaving the "Initialize this repository with a README" check blank

How do I create a branch using git and repo tools while working with android code

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?

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.

Categories

Resources