todo-git
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
todo-git [2012/03/20 23:59] – created dblume | todo-git [2021/11/02 21:48] – dblume | ||
---|---|---|---|
Line 31: | Line 31: | ||
git push origin | git push origin | ||
</ | </ | ||
+ | |||
+ | ===== Make a local clone of an existing remote project ===== | ||
+ | |||
+ | From the parent directory: | ||
+ | |||
+ | < | ||
+ | git clone https:// | ||
+ | cd python-interview | ||
+ | </ | ||
+ | |||
+ | ===== When it's time to commit ===== | ||
+ | |||
+ | **1.** Check which files are staged for commit. | ||
+ | |||
+ | < | ||
+ | git status | ||
+ | </ | ||
+ | |||
+ | **2.** Then, when you're ready to commit locally, | ||
+ | |||
+ | < | ||
+ | git commit -a -m "Some useful comment" | ||
+ | </ | ||
+ | |||
+ | **3.** When you're ready to push a local commit to a remote one... | ||
+ | |||
+ | < | ||
+ | git push -u origin master | ||
+ | </ | ||
+ | |||
+ | or | ||
+ | |||
+ | < | ||
+ | git push https:// | ||
+ | </ | ||
+ | |||
+ | ===== Creating a new remote repository from an existing local one ===== | ||
+ | |||
+ | I created hexbright-factory at [[https:// | ||
+ | |||
+ | < | ||
+ | touch README.md | ||
+ | git init | ||
+ | git add README.md | ||
+ | git commit -m "first commit" | ||
+ | git remote add origin https:// | ||
+ | git push -u origin master | ||
+ | </ | ||
+ | |||
+ | ===== Creating a new remote repository from an existing local one ===== | ||
+ | |||
+ | I created wine-tasting at [[https:// | ||
+ | |||
+ | < | ||
+ | ~$ 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:// | ||
+ | wine-tasting$ git push -u origin master | ||
+ | </ | ||
+ | |||
+ | ====== Renaming branches ====== | ||
+ | |||
+ | ===== Updating both local and remote repos ===== | ||
+ | |||
+ | 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 | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Creating a branch (and possibly pushing to upstream origin) ==== | ||
+ | |||
+ | $ git checkout -b new_branch | ||
+ | Switched to a new branch ' | ||
+ | |||
+ | That was the same as "'' | ||
+ | |||
+ | And now if you want to create that branch name at the remote branch, then: | ||
+ | |||
+ | $ git push --set-upstream origin new_branch | ||
+ | |||
+ | ==== Changing a local branch to a new remote branch ==== | ||
+ | |||
+ | This' | ||
+ | |||
+ | < | ||
+ | $ git checkout --track origin/ | ||
+ | </ | ||
+ | |||
+ | ==== Making the current local branch track a new remote branch ==== | ||
+ | |||
+ | < | ||
+ | $ git branch -u origin/ | ||
+ | </ | ||
+ | |||
+ | ===== Updating a local repo after remote' | ||
+ | |||
+ | <code bash> | ||
+ | git branch -m master main | ||
+ | git fetch origin | ||
+ | git branch -u origin/main main | ||
+ | git remote set-head origin -a | ||
+ | </ | ||
+ | |||
+ | ====== 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 | ||
+ | </ | ||
+ | |||
+ | Then, at the local computer: | ||
+ | |||
+ | <code bash> | ||
+ | testcode$ git init | ||
+ | Initialized empty Git repository in / | ||
+ | testcode$ git add . | ||
+ | testcode$ git commit -m "first commit" | ||
+ | ... | ||
+ | testcode$ git remote add origin ssh:// | ||
+ | testcode$ git push origin master | ||
+ | </ | ||
+ | |||
+ | I could' | ||
+ | |||
+ |