├── README.md ├── git-with-stata.stpr ├── scatter.do └── scatter.png /README.md: -------------------------------------------------------------------------------- 1 | ## Basic Stata and Git Workflow 2 | 3 | You can call Git from the Stata command prompt via the `shell` function. For 4 | more information on this command checkout the help documentation. 5 | 6 | ``` 7 | help shell 8 | ``` 9 | 10 | Basically, you can run any Git command from Stata by typing `shell` or `!` before it. 11 | 12 | For example, to initialise a Git repository in the current working directory you 13 | would have to run: 14 | 15 | ``` 16 | shell git init . 17 | ``` 18 | 19 | This will launch a Shell window and close it almost immediately. Although it may look like 20 | nothing has changed, the git repo has been initialised. To confirm, type: 21 | 22 | ``` 23 | dir .git/ 24 | ``` 25 | 26 | Which should display the contents of the hidden `.git/` directory that is present in all 27 | git repositories. 28 | 29 | You can then go on to create a `.gitignore`, stage files and commit changes. 30 | 31 | ### What are the main advantages of this way of doing things? 32 | 33 | - You get to stay within Stata and don't have to switch back and forth between 34 | Git bash and/or your favorite Git client. 35 | 36 | ### What are the main disadvantages? 37 | 38 | - No informative messages, that you would get by using another terminal, like Git Bash. 39 | - No automatic text complition with the `Tab` key. 40 | - No syntax highlighting. 41 | 42 | ## Here are the steps I took to create this little example 43 | 44 | 1. Create Stata project in a directory, create `README.md` file and write down 45 | instructions. 46 | 2. Initialise Git repository. 47 | 48 | ``` 49 | ! git init . 50 | ``` 51 | 3. Stage `README.md` and `.stpr` file and commit. 52 | 53 | ``` 54 | ! git add README.md git-with-stata.stpr 55 | ! git commit -m "Initial commit :hatching_chick:" 56 | ``` 57 | **Update**: It's [not a good idea to commit `.stpr` files](https://www.statalist.org/forums/forum/general-stata-discussion/general/1291117-wishlist-for-stata-15?p=1354726#post1354726). 58 | 59 | 4. Create little do file and run. 60 | 5. Stage do file and figure and commit. 61 | ``` 62 | ! git add scatter* 63 | ! git commit -m "Add a little example script and figure" 64 | ``` 65 | 6. Go to GitHub, create a repo with the same name, without initialising a README. 66 | Then locally add origin and push. 67 | ``` 68 | ! git remote add origin https://github.com/mpaulacaldas/git-with-stata.git 69 | ! git push --set-upstream origin master 70 | ``` 71 | 7. Update `README.md`, stage, commit and push. 72 | ``` 73 | ! git add README.md 74 | ! git commit -m "Update README" 75 | ! git push 76 | ``` 77 | -------------------------------------------------------------------------------- /git-with-stata.stpr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpaulacaldas/git-with-stata/dff677eb181fea9504b3a5945d16a2abe4d6e32c/git-with-stata.stpr -------------------------------------------------------------------------------- /scatter.do: -------------------------------------------------------------------------------- 1 | * Small example script 2 | 3 | webuse lifeexp 4 | graph twoway scatter lexp gnppc 5 | graph export scatter.png 6 | -------------------------------------------------------------------------------- /scatter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mpaulacaldas/git-with-stata/dff677eb181fea9504b3a5945d16a2abe4d6e32c/scatter.png --------------------------------------------------------------------------------