xxx git checkout is a local operation, nothing to do with remote repo xxx
//=== http://git-scm.com/book/en/v2/Git-Branching-Remote-Branches
* Remote branches are references (pointers) to the state of branches in your remote repos.
* Tracking Branches
Checking out a local branch from a remote branch "automatically creates"
a “tracking branch”
(or sometimes an “upstream branch”).
Tracking branches are local branches that have a direct relationship to a remote branch.
Both git checkout -b, git checkout --track will create "tracking branches"
$ git checkout -b [branch] [remotename]/[branch]
(-b implies --track)
$ git checkout --track origin/serverfix
Branch serverfix set up to track remote branch serverfix from origin.
Switched to a new branch 'serverfix'
* To set up a local branch with a different name than the remote branch,
$ git checkout -b mysrvfix origin/serverfix
Branch mysrvfix set up to track remote branch serverfix from origin.
Switched to a new branch 'mysrvfix'
* If you already have a local branch and want to set it to a remote branch,
or want to change the upstream branch you’re tracking, you can use the -u or --set-upstream-to
$ git branch -u origin/serverfix
Branch mylocalBranchCurrent set up to track remote branch serverfix from origin.
* ??? commit == check-in
//=== https://www.atlassian.com/git/tutorials/undoing-changes/git-checkout
//=== targets for git checkout
* files
* commits
* branches
"""...
Checking out a commit makes the entire working directory match that commit.
This can be used to view an old state of your project without altering your current state in any way.
Checking out a file lets you see an old version of that particular file,
leaving the rest of your working directory untouched.
...
unlike checking out a commit[the whole files],
this[check out a particular file] does affect the current state of your project.
The old file revision will show up as a “Change to be committed,”
giving you the opportunity to revert back to the previous version of the file
..."""
# checkout(or return to) the master branch
$ git checkout master
# Check out a particular file from a certain commit.
$ git checkout commit_id filename
# Check out all files from a certain commit.
git checkout commit_id
//=== http://git-scm.com/docs/git-checkout
# create a new branch
$ git checkout -b newbranch
$ git checkout -B nebranch [startpoint]
nebranch is created if it doesn’t exist;
otherwise, it is reset.
"transactional" equivalent to
(the branch is not reset/created unless "git checkout" is successful.)
$ git branch -f nebranch [start point]
$ git checkout nebranch
//=== http://gitready.com/intermediate/2009/01/09/checkout-remote-tracked-branch.html
$ git checkout --track -b branch_name origin/branch_name
or a simpler version:
$ git checkout -t branch_name origin/branch_name
??? always set the "branch.autosetupmerge" configuration flag to true,
so that branch tracking is done automatically when I do a "git checkout -b foo".
Creating a local branch and pushing it to remote is easy:
$ git branch localbranchname
$ git push origin localbranchname
but
there's a complication when you create a local branch / push it to remote
and want that local branch to track the remote branch.
To get the local branch to track the remote branch requires the deletion of the local branch
and pulling it from remote. This can be done with one line:
$ git branch -f localbranchname origin/remotebranchname
You must be on another branch for this to work since you can't delete the branch that you are on.
//=== git clean
https://www.atlassian.com/git/tutorials/undoing-changes/git-clean
"""...
git clean command removes untracked files from your working directory.
This is really more of a convenience command, since it’s trivial to see which files are untracked with git status and remove them manually.
Like an ordinary rm command, git clean is not undoable,
so make sure you really want to delete the untracked files before you run it.
The git clean command is often executed in conjunction with git reset --hard....
..."""
//=== http://git-scm.com/book/en/v2/Git-Branching-Remote-Branches
"""...
If you don’t want to type it every single time you push, you can set up a “credential cache”. The simplest is just to keep it in memory for a few minutes, which you can easily set up by running git config --global credential.helper cache.
..."""
2015年4月23日 星期四
git checkout and branch
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言