todo-git
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
todo-git [2014/06/08 23:11] – dblume | todo-git [2021/11/14 00:23] – [Updating a local repo after remote's already renamed its branch] dblume | ||
---|---|---|---|
Line 43: | Line 43: | ||
===== When it's time to commit ===== | ===== When it's time to commit ===== | ||
- | Check which files are staged for commit | + | **1.** |
+ | |||
+ | < | ||
+ | git status | ||
+ | </ | ||
+ | |||
+ | **2.** Then, when you're ready to commit locally, | ||
< | < | ||
Line 49: | Line 55: | ||
</ | </ | ||
- | When you're ready to push a local commit to a remote one... | + | **3.** |
+ | |||
+ | < | ||
+ | git push -u origin master | ||
+ | </ | ||
+ | |||
+ | or | ||
< | < | ||
Line 86: | Line 98: | ||
wine-tasting$ git push -u origin master | 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 --all --prune | ||
+ | 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' | ||
+ | |||
+ |