Cloning git repo - android

Today I cloned a Git repo successfully (I hope), however I can not see any source files in the cloned directory. To be specific I cloned the msm-kernel repo from Google with the command:
git clone https://android.googlesource.com/kernel/msm.git kernel_msm

The master branch of this repo is empty. You need to check out the proper branch:
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/android-msm-2.6.35
remotes/origin/master
$ git checkout android-msm-2.6.35
Checking out files: 100% (33866/33866), done.
Branch android-msm-2.6.35 set up to track remote branch android-msm-2.6.35 from origin.
Switched to a new branch 'android-msm-2.6.35'
$ ls
COPYING MAINTAINERS arch firmware ipc net sound
CREDITS Makefile block fs kernel samples tools
Documentation README crypto include lib scripts usr
Kbuild REPORTING-BUGS drivers init mm security virt
$

Apparently, master has no files. You have to checkout a branch:
git checkout --track -b android-msm-2.6.35 origin/android-msm-2.6.35

Related

Switching a branch type after commit

I have three branches, the main branch, the development branch and the new_feature branch.
The problem is I accidently set my first commit (initial commit)on the development branch.
Screenshot of my problem:
Full overview of my branches:
Question: How do I change it to the main branch?
As you haven’t merge remote branches (origin/development and origin/new_feature) into local repo. So there are two situations
Don’t need remote changes. Follow these steps:
Create a new “initial commit”. git checkout master, git checkout --orphan master1 and then git commit
Rebase development branch on it. git checkout development and git rebase master1 (if there has conflict file, you use to use git add filename and git rebase --continue).
Delete master and new_feature branch. git branch -D master and git branch -D new_feature
Rename branch. git branch -m master1 master, git checkout master and git branch new_feature
Force push to remote. git push -f --all
Need remote changes. Follow below steps:
Merge remote changes to local. git checkout development, git merge origin/development, git checkout new_feature, git merge origin/new_feature
Create a new “intial commit”. git checkout master, git checkout --orphan master1 and then git commit
Rebase development branch on it. git checkout developmen and git rebase master1
Rebase new_feature branch on it. git checkout new_feature and git rebase master1
Rename master branch. git branch -D master and git branch -m master1 master
Force push to remote. git push -f --all
You can merge your develop branch with your master branch or use the cherry-pick command from your master branch for retrieving your initial commit.
git push -u origin development//(push it up to development)
git checkout main //checkout local main branch
git pull origin development //Pull latest from remote development branch into main
git add -A
git commit -m "get latest from development"
git push -u origin //push up to main
You can rename your development branch.
$ git checkout development # checkout development
$ git checkout -b development-backup # backup development branch
$ git branch -D master # delete your current local master
$ git branch -m development master # rename development -> master
$ git checkout master # checkout master
$ git push -f origin master # force push, update remote master

Adding an existing android studio project to gitlab repository

I have a project in android studio that i want to commit to a gitlab repository. I have a link for this repository. What do i need to do, step for step, to add this project to said repository?
First you have to guarantee that this project is already a git repository on your local machine.
You can do this by checking if there's a folder .git in the directory. If there's none, do the following command:
# create a git repository on the current directory
git init
After that you need to make your repository point to gitlab
git remote add origin "url from gitlab"
Add files for your initial commit
git add -A
Commit the files
git commit -m "your initial commit message"
Push all the files to the remote(gitlab)
git push -u origin master
More information of each command can be found typing:
man git command
# example
man git push
For using gitlab when you have ssh keys and also your ssh key have passphrase, you have to follow instructions as follow (don’t forget to upload your public key to gitlab)(also you must use a private key which its format is openssh):
Have your project folder and its files.
Have Git Bash installed on your system.
Using git bash, go to your project directory.
git config --global user.name "your-name"
git config --global user.email "your-email-address"
git init
ssh-agent bash -c 'ssh-add “private-key-local-address”; git remote
add origin “online-repo-address”’ (will be asked for passphrase)
git add .
git commit -m “initial commit”
ssh-agent bash -c 'ssh-add “private-key-local-address”; git push
-u origin master' (will be asked for passphrase)
For further commits, you can commit changes in android studio and then repeat step 10 to push them to gitlab servers.

How to download only a working directory of the AOSP source code without the entire repo history?

The size of the latest AOSP source code is rather large (around 30-35 Gb for the .repo directory and another 15 Gb or so for the working directory). Is there a way to download only a snapshot of the latest version of the source code (official marshmallow release) without the entire repo history? That would save me a lot in bandwidth and storage.
You can specify --depth 1 to git clone command. It will only get the latest snapshot.
Step to download android source code(AOSP) in Ubuntu
First create one folder like "aosp-m" to copy AOSP code in your machine.
Open terminal(Ctrl+Alt+T) and change your Dir to latest created Dir let say "aosp-m"
After that Run the following command in terminal :-
git clone git://gitz01/cm/download/android/manifest
if this link not work then try this one
repo init -u https://android.googlesource.com/platform/manifest
Run Following command in terminal one by one
git config --global user.name "Your Name"
git config --global user.email "you#example.com"
then run following command for repo init
repo init -u git://gitz01/cm/download/android/manifest -b master -m identifiedmanifest.xml
if this link not work then try this one
repo init --depth=1 -u https://android.googlesource.com/platform/manifest -b identifiedmanifest.xml
here you can replace identifiedmanifest.xml to your desired AOSP source code , Let Say "android-6.0.1_r10.xml" marshmellow.
and in the last run "repo sync" command. This command start downloading your desired AOSP code in your machine. This opertation take more than 1 hours(depending on your internet connection speed) to download source code.
Thats it... Happy Coding.......
Since git version 2.19 (released in 2018), we can utilize git's --partial-clone flag via the repo tool like the following:
repo init -u https://android.googlesource.com/platform/manifest -b master --partial-clone --clone-filter=blob:limit=10M
For readers of this question and answer in 2020, be warned that the AOSP repositories have gotten bigger and the above command still results in around 73 gigabytes of source code and related files.

Git for my Remote Server for an Android Application

I'm running a remote Linode server - Debian 7.5 Profile (Latest 64 bit (3.16.5-x86_64-linode46))
A co-worker of mine already has an android application project locally on their machine.
I want to be able to transfer that project onto my server and adapt the git technology to it. So that it will enable me and the colleague to simultaneously work on the project.
How can I achieve this?
Are there any step by step tutorials on how to do this?
Thanks in advance
You might want to read this for using git on the server.
http://git-scm.com/book/en/v1/Git-on-the-Server
Tip. If you guys can use a shared folder (e.g., samba shared folder), just keep the common git repository there. Then you guys can clone it and push commits into the git not shared folder.
$ git clone samba_shared_folder_path
You can understand why it works after reading the above link.
Tip2, You can try the following at you local. (Just forget about 4-digit number)
a. make a local git repo and a commit
2037 mkdir common
2038 cd common/
2039 git init
2040 touch sample.txt
2041 git add sample.txt
2043 git commit -m "testing"
b. clone the commit.git into another folder
2044 cd ..
2045 git clone common my_common
2046 cd my_common/
2047 echo "new line" >> sample.txt
2048 git add sample.txt
2049 git commit -m "new commit from my_common"
c. push new commit from my_common(local) into common(remote)
2052 git push ../common HEAD:from_new_common
Just think about using a shared folder instead of common folder at your local.

How to run git command to specific projects

I want to run a git command only to specific repositories.
I know 'repo forall' will help to run a command to all the git projects in that repo.
But, I want to run on specific projects.
For an example.
repo forall -c "git checkout -t remotes/origin/TESTBRANCH"
Will run the git command to checkout to TESTBRANCH for all projects.
But I want to checkout only few projects,
1. kernel
2. frameworks/av
3. hardware/qcom/media.
Tried as below,
repo forall -c "git checkout -t remotes/origin/TESTBRANCH" kernel frameworks/av hardware/qcom/media`
But, not working. Can anyone help?
As indicated by the documentation (repo help forall), the project names should go before the -c option:
repo forall kernel frameworks/av hardware/qcom/media \
-c "git checkout -t remotes/origin/TESTBRANCH"

Categories

Resources