# GIT CHEATSHEET ## By Sharvil (20240927) Perform these steps on creating a new project. _**ASSUMPTION:** You are already in your project directory in the command line terminal._ --- ### STEP 0. #### Initialize Git in your new project: Do this when creating a new project directory. Do this **ONLY ONCE**. ```commandline git init ``` ### STEP 1. #### Create a `.gitignore` file: Add files/directories in it which you don't want to sync to git. Update this as frequently as your project needs you to. Start with this: ``` /.venv/ /.idea/ **/__pycache__/ __pycache__/ *.pem *.pyc *.pyd ``` ### STEP 2. #### Create a repository on Gitea (web UI): Do this **ONLY ONCE**. Open the following URL: https://wtt.ditscentre.in/ and sign in. - Ensure that the owner is `ditscentre` (img 0). - Give your repository a name. Preferably keep it the same as the project name that you made locally (img 0). - Type in a brief description of your project (img 0). ![img 0](https://nexcom.ditscentre.in/utils/files/small/download/66f66a54196705ee2f25d28e) - Ensure that the default branch is `master` (img 1). - Create the repository (img 1). ![img 1](https://nexcom.ditscentre.in/utils/files/small/download/66f66a54196705ee2f25d28f) ### STEP 3. #### Add files and directories to the staging area: The following command adds everything to the staging area. The '.' is important, it refers to the current directory. ```commandline git add . ``` ### STEP 4. #### Commit the changes to local git: This step commits all the added (staged) changes to the local git instance with the provided comment. ```commandline git commit -m "you comment here..." ``` ### STEP 5. #### We push the local commits to the repository: The format of the command is: ``` git push -u ``` --- ## For Python Devs: How to add a common subtree (like `utils_v2`) The format of the command is: ``` git subtree add --prefix= --squash ``` Before you start: ensure that you have committed all pending changes. Then run the following command **ONLY ONCE**: ```commandline git subtree add --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master --squash ``` This will create a new directory named `utils_v2` in your project. **Do NOT change the files in it.** Just import and use them in your scripts. When you need to get the latest updates to these files, you must run a modification of the previous command: ```commandline git subtree pull --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master --squash ```