Difference between revisions of "Git phrasebook"
Paulproteus (talk | contribs) (→Creating a new local branch that tracks a remote branch) |
Frank Tobia (talk | contribs) (undoing a git-add) |
||
Line 44: | Line 44: | ||
cd .. # top level of project | cd .. # top level of project | ||
git add path/to/submodule # NOTE: No trailing slash! | git add path/to/submodule # NOTE: No trailing slash! | ||
+ | |||
+ | == Undoing a git-add == | ||
+ | git reset | ||
+ | will clear out your index, in case you git-add'd something that you didn't want to. |
Revision as of 22:20, 9 July 2008
Everything in ALLCAPS should be considered something you think about before typing.
Contents
- 1 Checking out a project
- 2 Creating a new local branch that tracks a remote branch
- 3 Switching which branch you are on
- 4 Making a local branch available as a remote branch
- 5 Configuring git to push a particular local branch to a particular remote branch every time you call "git push"
- 6 Deleting a remote branch
- 7 Adding a new version of a submodule to the git index
- 8 Undoing a git-add
Checking out a project
git clone PROJECT_URL git branch -a # Take a look at all the remote branches you can pick from.
Creating a new local branch that tracks a remote branch
Assuming you want to pull from the remote called "origin":
git branch --track LOCALFUN origin/REMOTE_BRANCH_NAME git checkout LOCALFUN git pull # You should see, "Already up-to-date." git push # You should see, "Everything up-to-date"
However, FIXME!
The push does nothing. :-(
Switching which branch you are on
git checkout <BRANCH_NAME>
NOTE: Do not use this to create branches!
Making a local branch available as a remote branch
git push origin LOCAL_BRANCH_NAME:refs/heads/REMOTE_BRANCH_NAME
Configuring git to push a particular local branch to a particular remote branch every time you call "git push"
Edit .git/config. Look for [remote "origin"].
Inside there, add:
push = refs/heads/LOCAL_BRANCH_NAME:refs/heads/REMOTE_BRANCH_NAME
Two important notes:
- You may have as many push lines as you like. Every "git push" with no arguments will push all of them.
- LOCAL_BRANCH_NAME and REMOTE_BRANCH_NAME are often the same, but naturally do not have to be.
Deleting a remote branch
git push origin :BRANCH_NAME_TO_DELETE
Adding a new version of a submodule to the git index
cd path/to/submodule git checkout origin/WHICHEVER_BRANCH_YOU_WANT cd .. # top level of project git add path/to/submodule # NOTE: No trailing slash!
Undoing a git-add
git reset
will clear out your index, in case you git-add'd something that you didn't want to.