Difference between revisions of "Git Commands"
(Created page with "==Git commands== In particular useful with GitHub ====Create new branch==== git branch branchname ====Select a branch to work on it==== git checkout branchname ====Delet...")
Revision as of 15:25, 1 March 2012
- 1 Git commands
- 1.1 Create new branch
- 1.2 Select a branch to work on it
- 1.3 Delete a branch
- 1.4 Delete a remote branch
- 1.5 Fetch updates from a remote repository
- 1.6 Download (fork) a remote repository
- 1.7 Download a branch from a different remote site
- 1.8 Upload committed changes to a remote repository
- 1.9 Rename a branch
- 1.10 Create multiple pull requests (in GitHub)
In particular useful with GitHub
Create new branch
git branch branchname
Select a branch to work on it
git checkout branchname
Delete a branch
git branch -D branchname
Delete a remote branch
By default branches are not deleted from a remote site, even not with a
git push --all.
git push remotename :branchname git push origin :branchname
Fetch updates from a remote repository
git pull git pull origin git pull --all
Download (fork) a remote repository
git clone remote-url git clone firstname.lastname@example.org:macfreek/some-project.git
Download a branch from a different remote site
git remote add branchname remote-url git remote add camblor https://github.com/macfreek/some-project.git
This will create branches under the macfreek/ prefix, e.g. macfreek/origin, macfreek/v1.4 etc.
Upload committed changes to a remote repository
git push git push origin
Rename a branch
git branch -m oldname newname
Create multiple pull requests (in GitHub)
Imagine you have made four commits, and want to create two separate pull requests.
In this example branch
topic1 contains commits B and C, while branch
topic2 should only contain commits D and E.
A upstream/master -- B -- C topic1 -- D -- E topic2
Making a pull request for topic1 works as expected, but a pull request for topic2 will contain commits B, C, D and E. Not just D and E.
The solution is to create a new branch and to cherry-pick commits D and E:
git branch -b topic2_req upstream/master git cherry-pick sha1_D sha1_E git push origin topic2_req