Home > Software design >  How to update my project in Android Studio with git data of specific releases version from a remote
How to update my project in Android Studio with git data of specific releases version from a remote

Time:05-29

I've installed a specific release version from a remote repository on Gitlab by installing the zip without cloning, I made changes and now I want to do a merge request of a new branch for my changes. but I am unable to create a new branch (locally), I guess I need to install the info or tracking data from git and add it to the file, how to do that?

Notice I am not using the command line for this, I am just looking for generic instructions.

CodePudding user response:

An altenrative would be to move your existing local folder, clone the repository, and import your moved local folder:

move myRepo myRepo.ori
git clone https://gitlab.com/me/MyRepo
cd myRepo
git switch -c myBranch
git --work-tree=../myRepo.ori add .
git commit -m "Import work"
git push -u origin myBranch

Note that with Git 2.37 (Q3 2022) and a git branch --set-upstream my_branch origin/my_branch, you won't have to use -u on your first push anymore.

git push will be enough to establish a remote tracking branch with origin/myBranch.

CodePudding user response:

You can't. Downloading a zip file instead of cloning a Git repository is a dead-end path. Don't do that (unless you want to stop at this dead end, of course, but in this case you do not want that).

You can recover from this mistake though. Start by forking on GitLab, and then cloning to your laptop (or whatever local computer), the repository in question, into a new location on your laptop, keeping your modified version separate from the new clone. You now have three things:

  • a Git fork (on GitLab);
  • a Git repository (on your laptop) with a working tree; and
  • a tree that's not part of a Git repository (also on your laptop).

Using the clone on your laptop, check out whichever branch it was that you used to make the original zip file. Note that none of these steps need to happen inside Android Studio (which I don't use and cannot say more about).

Now, using the command line (whose prompt I will pretend, here, is a simple dollar sign $), you can do this in your new clone:1

$ git rm -r .
$ cp -r /path/to/zip/dir .
$ git add .
$ git status

The result of this git status should show your changes as "changes staged for commit". Use git diff --staged to view those changes as changes, from the command line, or re-start Android Studio in this clone if you prefer to work in an IDE. You can now make a new commit, use git push to send the new commit to your GitLab fork, and use GitLab to make a Merge Request.

Once you are fully satisfied that your Git repository work is working the way you would like it to, it is then safe to completely remove the unzipped files you made and edited earlier. Until then, that's acting as a backup while you get yourself started with Git.


1I assume here that you have a Linux-like system. If not, you may need to adapt the non-Git commands.

  • Related