|
| 1 | +## Common git commands: |
| 2 | + 0. `git clone <https://github.com/some_repo/some_repo.git>` Obtain exact copy of repo from github |
| 3 | + 1. `git add <file>` Adds local file to git tracking |
| 4 | + 2. `git log` Shows local history of commits |
| 5 | + 3. `git status` Shows any changes to local files, in addition to any untracked files |
| 6 | + 4. `git commit -m "text message"` Commits any files that have been added to stage with message |
| 7 | + 5. `git commit -a` Adds then commits all changes in tracked files |
| 8 | + 6. `git pull <remote> <branch>` Merges github history to local, taken from remote (usually origin) and branch (often master). |
| 9 | + 7. `git push <remote> <branch>` Moves local commits to github repository at remote/branch |
| 10 | + 8. `git checkout -b <branch_name>` Makes a new branch and switch to it |
| 11 | + 9. `git checkout <branch_name>` Move to branch_name |
| 12 | + 10. `git branch` Lists branches, shows which branch you are on |
| 13 | + 11. `git branch -d` Delete branch locally |
| 14 | + 12. `git push <remote> :<branch_name>` Deletes branch on remote. |
| 15 | + 13. `git checkout <file>` Reverts any changes in `file` to state determined by current git hash |
| 16 | + 14. `git init` Create a new git repository |
| 17 | + 15. `git remote add origin <server>` Connects repository to a remote server |
| 18 | + 16. `git diff` View all local changes relative to remote |
| 19 | + 17. `git rm` Removes a tracked file |
| 20 | + 18. `git remote -v` Shows identity of origin and other remotes |
| 21 | + 19. `git remote add upstream <parent repo>` Adds upstream remote for a parent repo |
| 22 | + |
| 23 | + |
| 24 | +## Making a new repo |
| 25 | +1. First make repo on github |
| 26 | +2. `git clone` your new repo locally. |
| 27 | +3. Make some new file, `file.dat` |
| 28 | +4. See your new untracked file: `git status` |
| 29 | +5. Stage file for commit: `git add file.dat` |
| 30 | +6. Commit change, enter message, close file: `git commit -a` |
| 31 | +7. See your new history!: `git log` |
| 32 | +8. Push your changes to your repo on github.com: `git push origin master` |
| 33 | + |
| 34 | +## Making a fork |
| 35 | +### Good practice for making changes to shared code |
| 36 | +1. On a parent repo page in github.com, click Fork on the top right. |
| 37 | +2. Clone to local machine: `git clone <your fork>` |
| 38 | +3. Setup upstream: `git remote add upstream <parent repository>` |
| 39 | +4. Make a branch of your fork: `git checkout -b new_branch` (branch name should be descriptive of changes) |
| 40 | +5. Make some local change: `vi new_file.dat` |
| 41 | +6. Add and commit change: `git add new_file.dat`, `git commit -m "Add new file"` |
| 42 | +7. Rebase to resolve any merge conflicts: `git pull --rebase upstream master` |
| 43 | +8. If your local branch differs from origin, you will need to make your changes and then push with force: |
| 44 | +`git push --force origin new_branch` |
| 45 | +9. Push changes: `git push origin new_branch` (this will create a new branch on github.com) |
| 46 | +10. On your fork on github.com, create a pull request pushing the "Compare & pull request" button. |
| 47 | +11. Open the pull request by by writing a description and clicking "Create pull request" |
| 48 | +12. Delete branch once PR is merged |
0 commit comments