--- tags: GeneLab --- # A few key git command-line commands [toc] --- ## Short Overview * **Getting a repository on our local computer** * `git clone https://github.com/asaravia-butler/GeneLab_Data_Processing.git` * **Checking the status** * `git status` * **Changing branches** * `git branch` (another way to check which branch we are currently on) * `git checkout mikes-branch` (change to different branch) * **Making and uploading changes** 1. Make changes * `mkdir temp` * `touch temp/test.txt` <br> 2. *Add* the changes * `git add *` (can also specify individual files or directories) * `git status` <br> 3. *Commit* the changes * `git commit -m "adding test file for example"` * `git status` <br> 4. *Push* the changes * `git push` * `git status` * See [here](https://stackoverflow.com/a/35942890/10452709) if wanting to store username and password. --- ## Longer overview with more words :) ### Getting a repository on our local computer We want to copy the URL from the repository's main page under the "Code" dropdown menu: ![](https://i.imgur.com/2EiDEit.png) and provide it to `git clone`, e.g.: ```bash git clone https://github.com/asaravia-butler/GeneLab_Data_Processing.git ``` This "clones" the repository, including the magic git directory that holds all information about the repository and tracks all changes, `.git`: ![](https://i.imgur.com/uTTdW49.png) ### Checking the status `git status` tells us things like what branch we are on and if we have any changes that the online repository doesn't have. We'll see it's use as we go. Right now it says we are on the master branch and that we have no changes in our local version yet. ```bash git status ``` ![](https://i.imgur.com/tqZbBzH.png) ### Changing branches We can also see what branch we're on with `git branch`, and can change branches with `git checkout <branch-name>`, e.g.: ![](https://i.imgur.com/V1AGsgj.png) ### Making and uploading changes 1. Make changes 2. *Add* the changes (`git add <whatever>`) 3. *Commit* the changes (`git commit -m "commit message"`) 4. *Push* the changes to the online repository (`git push`) #### 1. Make changes We can make changes to any files, or add or remove any files, on our local computer now. E.g., we'll add a temporary directory here with a test file: ```bash mkdir temp touch temp/test.txt git status ``` ![](https://i.imgur.com/D2w5Y2r.png) #### 2. *Add* the changes We now tell the magic `.git` directory which of the changes we've made we want it to pay attention to, wildcard characters work, e.g.: ```bash git add * git status ``` ![](https://i.imgur.com/3Gb5cRN.png) This is also known as being "staged" to be committed. #### 3. *Commit* the changes This officially changes our local version of the repository, and we need to provide a short commit message saying what we're doing: ```bash git commit -m "adding test file for example" git status ``` ![](https://i.imgur.com/PlDo4yX.png) Note that now `git status` tells us our branch is one 1 commit ahead of the online version. #### 4. *Push* the changes to the online repository Now we update the online repository to match what is on our local version. > If we want to store our username and password, so we don't need to enter them each time, see [here](https://stackoverflow.com/a/35942890/10452709). ```bash git push git status ``` ![](https://i.imgur.com/9LDTC2l.png) And if we look online, we can see the new directory and test file are there: ![](https://i.imgur.com/WInrLRS.png) ---