[[git]]
 

Differences

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

Link to this comparison view

todo-git [2012/10/19 01:09]
dblume
todo-git [2017/03/10 23:31] (current)
dblume [Renaming branches]
Line 30: Line 30:
 <code> <code>
 git push origin git push origin
 +</code>
 +
 +===== Make a local clone of an existing remote project =====
 +
 +From the parent directory:
 +
 +<code>
 +git clone https://github.com/realpython/interview-questions.git python-interview
 +cd python-interview
 </code> </code>
  
 ===== When it's time to commit ===== ===== When it's time to commit =====
  
-Check which files are staged for commit with ''git status'' Then, when you're ready to commit locally,+**1.** Check which files are staged for commit
 + 
 +<code> 
 +git status 
 +</code> 
 + 
 +**2.** Then, when you're ready to commit locally,
  
 <code> <code>
Line 40: Line 55:
 </code> </code>
  
-When you're ready to push a local commit to a remote one...+**3.** When you're ready to push a local commit to a remote one... 
 + 
 +<code> 
 +git push -u origin master 
 +</code> 
 + 
 +or
  
 <code> <code>
 git push https://github.com/dblume/netflix-dvd-feed git push https://github.com/dblume/netflix-dvd-feed
 </code> </code>
 +
 +===== Creating a new remote repository from an existing local one =====
 +
 +I created hexbright-factory at [[https://github.com/new]].  Then, to create a new repository on the command line at the local computer:
 +
 +<code>
 +touch README.md
 +git init
 +git add README.md
 +git commit -m "first commit"
 +git remote add origin https://github.com/dblume/hexbright-factory.git
 +git push -u origin master
 +</code>
 +
 +===== Creating a new remote repository from an existing local one =====
 +
 +I created wine-tasting at [[https://github.com/new]].  Then, to create a new repository on the command line at the local computer:
 +
 +<code>
 +~$ mkdir wine-tasting
 +~$ cd wine-tasting/
 +wine-tasting$ vim README.md
 +wine-tasting$ vim LICENSE.txt
 +wine-tasting$ git init
 +wine-tasting$ git add README.md
 +wine-tasting$ git add LICENSE.txt
 +wine-tasting$ git add test.py
 +wine-tasting$ git add wine_allocator.py
 +wine-tasting$ git commit -m "first commit"
 +wine-tasting$ git remote add origin https://github.com/dblume/wine-tasting.git
 +wine-tasting$ git push -u origin master
 +</code>
 +
 +====== Renaming branches ======
 +
 +To rename a remote branch:
 +
 +  - Rename the local one.
 +  - Push the deletion of the old name.
 +  - Push the new name.
 +  - git remote prune origin
 +
 +When someone else renamed a remote branch:
 +
 +<code bash>
 +$ git fetch --all  # TODO investigate why fetch
 +$ git remote prune origin  # (where origin is the name of the shared repo)
 +</code>
 +
 +
 +==== Changing a local branch without regard to remote branch ====
 +
 +<code>
 +$ git checkout -b branch_name
 +Switched to a new branch 'branch_name'
 +</code>
 +
 +That was the same as "git branch branch_name; git checkout branch_name"
 +
 +==== Changing a local branch to a new remote branch ====
 +
 +This'll work if you don't have a local branch with that name already.
 +
 +<code>
 +$ git checkout --track origin/branch_name
 +</code>
 +
 +==== Making the current local branch track a new remote branch ====
 +
 +<code>
 +$ git branch -u origin/branch_name
 +</code>
 +
 +
 +
 +====== git at dlma.com ======
 +
 +I created a remote git repo at dlma like so:
 +
 +At the server:
 +
 +<code bash>
 +git$ mkdir testcode.git
 +git$ cd testcode.git/
 +testcode.git$ git init --bare
 +</code>
 +
 +Then, at the local computer:
 +
 +<code bash>
 +testcode$ git init
 +Initialized empty Git repository in /home/David/testcode/.git/
 +testcode$ git add .
 +testcode$ git commit -m "first commit"
 +...
 +testcode$ git remote add origin ssh://USERNAME@dlma.com/~/git/testcode.git
 +testcode$ git push origin master
 +</code>
 +
 +I could've use gitweb but I used GitHub-like [[https://github.com/klaussilveira/gitlist|gitlist]] at http://git.dlma.com.
 +
 +
todo-git.1350634143.txt.gz · Last modified: 2012/10/19 01:09 by dblume
 
Recent changes RSS feed Driven by DokuWiki