Xfce Wiki

Sub domains
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dev:howto:git-tips-and-tricks [2009/08/14 00:42]
kelnos created; moved from subsection of dev:howto:git
dev:howto:git-tips-and-tricks [2010/10/02 17:26] (current)
Line 48: Line 48:
   - Using '​matching'​ will push **all** local branches that exist on the server. ​ If you had some commits in another local tracking branch that you forgot about but didn't want to push yet, these will get pushed anyway.   - Using '​matching'​ will push **all** local branches that exist on the server. ​ If you had some commits in another local tracking branch that you forgot about but didn't want to push yet, these will get pushed anyway.
   - Using '​tracking'​ will only push the current branch, and then only if the branch already exists on the server. ​ Yes, this means if you want to push multiple branches you have to push several times, but how often do you need to do that?  It also means that if you're pushing a new branch, you have to explicitly name the branch on the command line the first time you push it, but, again, how often do you do that?   - Using '​tracking'​ will only push the current branch, and then only if the branch already exists on the server. ​ Yes, this means if you want to push multiple branches you have to push several times, but how often do you need to do that?  It also means that if you're pushing a new branch, you have to explicitly name the branch on the command line the first time you push it, but, again, how often do you do that?
 +
 +===== Pushing to a New Repository =====
 +
 +Git, annoyingly, requires you to know a few magic incantations when you push code to a brand-new remote repository. ​ We'll assume that you've already created a local repository using ''​git init'',​ have added files with ''​git add'',​ and have made some commits with ''​git commit''​. ​ After that, you need to add a remote to point to the repository on the server. ​ By convention, the default remote is called ''​origin'':​
 +
 +<​code>​git remote add origin $REPOSITORY_URL</​code>​
 +
 +Of course, replace ''​$REPOSITORY_URL''​ with the URL of the repo you want to push to.
 +
 +If the remote repository is completely empty and has no commits in it, you have to explicitly tell git what source branch you want to push (''​master''​) and where it should go on the remote (''​refs/​heads/​master''​):​
 +
 +<​code>​git push origin master:​refs/​heads/​master</​code>​
 +
 +From now on, all you'll have to do is ''​git push origin''​. ​ If you want to make it even easier, you can set up some configuration to automatically decide where to push:
 +
 +<​code>​git config branch.master.remote origin
 +git config branch.master.merge refs/​heads/​master</​code>​
 +
 +From now on, you can just do ''​git push''​ and it will know what to do.  When you clone a remote repository, these two configuration entries are set up for you automatically,​ but since you started with a self-created local repository, this couldn'​t happen.