Difference between revisions of "Git"
From neil.tappsville.com
Jump to navigationJump to searchm |
m |
||
Line 1: | Line 1: | ||
+ | ===Everyday=== | ||
+ | Stage and Add are the same. | ||
+ | git add <filename> | ||
+ | |||
+ | <pre> | ||
+ | git status | ||
+ | On branch mediatorLogging | ||
+ | Your branch is up to date with 'origin/mediatorLogging'. | ||
+ | |||
+ | nothing to commit, working tree clean | ||
+ | </pre> | ||
+ | |||
+ | git commit | ||
+ | |||
+ | git push | ||
===Local Changes vs Repo=== | ===Local Changes vs Repo=== | ||
git log origin/master..HEAD | git log origin/master..HEAD | ||
Line 25: | Line 40: | ||
* Delete source branch when merge request is accepted | * Delete source branch when merge request is accepted | ||
* Squash commits when merge request is accepted | * Squash commits when merge request is accepted | ||
+ | |||
+ | |||
+ | https://stackoverflow.com/questions/4470523/create-a-branch-in-git-from-another-branch | ||
+ | |||
+ | $ git checkout -b myFeature dev | ||
+ | Creates MyFeature branch off dev. Do your work and then | ||
+ | |||
+ | $ git commit -am "Your message" | ||
+ | Now merge your changes to dev without a fast-forward | ||
+ | |||
+ | $ git checkout dev | ||
+ | $ git merge --no-ff myFeature | ||
+ | Now push changes to the server | ||
+ | |||
+ | $ git push origin dev | ||
+ | $ git push origin myFeature | ||
+ | |||
+ | |||
+ | ===Updating a forked repo=== | ||
+ | https://help.github.com/en/articles/syncing-a-fork | ||
+ | <pre> | ||
+ | git remote add upstream https://github.com/wanduow/openli.git | ||
+ | |||
+ | $ git fetch upstream | ||
+ | remote: Enumerating objects: 62, done. | ||
+ | remote: Counting objects: 100% (62/62), done. | ||
+ | remote: Compressing objects: 100% (8/8), done. | ||
+ | remote: Total 85 (delta 56), reused 60 (delta 54), pack-reused 23 | ||
+ | Unpacking objects: 100% (85/85), done. | ||
+ | From https://github.com/wanduow/openli | ||
+ | * [new branch] develop -> upstream/develop | ||
+ | * [new branch] master -> upstream/master | ||
+ | |||
+ | git checkout master <---- go into master -- we will merge something into here. | ||
+ | git diff HEAD..upstream/master <--- see what we are missing | ||
+ | git merge upstream/master <---- merge this into the branch we have checked out | ||
+ | </pre> |
Revision as of 04:14, 1 November 2019
Everyday
Stage and Add are the same.
git add <filename>
git status On branch mediatorLogging Your branch is up to date with 'origin/mediatorLogging'. nothing to commit, working tree clean
git commit
git push
Local Changes vs Repo
git log origin/master..HEAD
You can also view the diff using the same syntax
git diff origin/master..HEAD
Diff between the current branch and develop (origin of this branch hopefully) aka diff source and then current branch
git diff develop..feature/[branch_name]
If working in master (no branches used)
git diff origin/master...HEAD
Wipe all local changes and get the latest from the repo
git reset --hard or git checkout -- <file name> git rebase origin/master
Or to store changes and re-apply them after pulling
git stash git pull git stash pop
Merge
Ensure the following are selected:
- Delete source branch when merge request is accepted
- Squash commits when merge request is accepted
https://stackoverflow.com/questions/4470523/create-a-branch-in-git-from-another-branch
$ git checkout -b myFeature dev
Creates MyFeature branch off dev. Do your work and then
$ git commit -am "Your message"
Now merge your changes to dev without a fast-forward
$ git checkout dev $ git merge --no-ff myFeature
Now push changes to the server
$ git push origin dev $ git push origin myFeature
Updating a forked repo
https://help.github.com/en/articles/syncing-a-fork
git remote add upstream https://github.com/wanduow/openli.git $ git fetch upstream remote: Enumerating objects: 62, done. remote: Counting objects: 100% (62/62), done. remote: Compressing objects: 100% (8/8), done. remote: Total 85 (delta 56), reused 60 (delta 54), pack-reused 23 Unpacking objects: 100% (85/85), done. From https://github.com/wanduow/openli * [new branch] develop -> upstream/develop * [new branch] master -> upstream/master git checkout master <---- go into master -- we will merge something into here. git diff HEAD..upstream/master <--- see what we are missing git merge upstream/master <---- merge this into the branch we have checked out