Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between repo start and git checkout -b

Doing some work in the Android Kernel. I am very familiar with git, but not extraordinarily familiar with repo, so I read the following document: http://source.android.com/source/version-control.html. To my understanding from it, as well as experimenting around with topic branches, repo start BRANCH_NAME is the same as git checkout -b BRANCH_NAME. Am I correct in my understanding, or are there some subtle, important details that I am missing?

like image 532
Brent Hronik Avatar asked Feb 21 '13 23:02

Brent Hronik


People also ask

What is the difference between repo and git?

Git is an open-source version-control system designed to handle very large projects that are distributed over multiple repositories. In the context of Android, we use Git for local operations such as local branching, commits, diffs, and edits. Repo is a tool that we built on top of Git.

What is git checkout and git checkout?

The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.

What is difference between git checkout and clone?

git clone is to fetch your repositories from the remote git server. git checkout is to checkout your desired status of your repository (like branches or particular files). E.g., you are currently on master branch and you want to switch into develop branch.

How does git checkout work internally?

With the git checkout command, we can move the HEAD to any commit in the repository we want. When the HEAD moves to a different commit, both the index and the working directory is updated to reflect the state of the files up to that commit. This command will move the head to the previous commit.


2 Answers

The difference is that repo start sets the remote and merge properties for your branch inside of .git/config:

[branch "YOUR_BRANCH_HERE"]
    remote = aosp
    merge = master

Without these, repo won't know how to properly upload your change when you run repo upload later, and it will act as if your new branch simply doesn't exist.

(There's also some logic in there that lets you create the new branch for every project in the repo simultaneously with --all, but that's just a convenience thing.)

like image 142
Trevor Johns Avatar answered Sep 30 '22 15:09

Trevor Johns


Looking at the start.py source code for repo start, I believe the main difference is in the management of the manifest files which are included in Android projects.

begins a new branch of development, starting from the revision specified in the manifest.


To add to Trevor Johns' answer, you need to check "How do you make an existing Git branch track a remote branch?" (when you are not using repo start):

git checkout -b newBranch -t aosp/master

That will set remote and merge (-t = "track") in the config associated to the new branch.

A simple git checkout -b wouldn't set anything, and create a purely local branch (without tracking any upstream branch to a remote repo)

like image 21
VonC Avatar answered Sep 30 '22 15:09

VonC