OSDC Lesson 4: My project on GitHub
Tags: osdc, opensource
Published: 2023-02-03 19:35:36

---
series: OSDC
---
# Place my own project on GitHub
Enter my project's dir
```
cd <my-proj>
```
Add the project to git and create the repository
```
git init
```
a **.git** directory will be created
```
ls -l
```
Check the status of the git
```
git status
```
Add all files to the staging
```
git add .
```
Remove a file which I don't want to track on git from staging (e.g. python's cache file)
```
git reset <file>
```
OR
```
git rm --cached <file>
```
### git alias
Add the following to the  `~/.gitconfig` file.
```
[alias]
    st = status
    co = checkout
    ci = commit
```
### git ignore
Add to the `.gitginore` file a list of files or folders that you want git to ignore, e.g. `__pycache___`
```
vi .gitignore
```

Add the `.gitignore` file to git
```
git add .gitignore
```

All the above referred to the local copy of my new git project. 

## Create a git project on GitHub

* Go to your [user's GitHub page](https://github.com/ShulyAvraham)
* On the top right click `+`->`New repository`
* Provide `repository name` - preferably with your project's root dir name (but not mandatory).
* Select Public or Private (I selected Public)
* Add a `README` file or `.gitignore`
    * if I started with creating the project in GitHub and then clone it - I will select to add `README` and `gitignore` files.
    * In my case, where I first created the repository locally, using the `git init` command and only then I careted the remote repo, I will choose not to add `README` and `.gitignore` files.
* Click `Create repository` (empty one)
* I will be provided instructions for connecting the remote with my local repositories.

### Connect the remote and local repositories
Go back to the project root dir on the command line
```
git remote add origin git@github.com:ShulyAvraham/LIMS_results_validation.git
git remote -v
```

This will add the following lines to the `.git/config` file
```
[remote "origin"]
        url = git@github.com:ShulyAvraham/LIMS_results_validation.git
        fetch = +refs/heads/*:refs/remotes/origin/*
```

### Map my branch to `main`
```
git branch -M main
```

### Push repo to remote
The name of the remote is `origin` and the remote branch is `main`. The -u configs git to map this connection for later pushes.
```
git push -u origin main
```
This will add the following to the `.git/config` file
```
[branch "main"]
        remote = origin
        merge = refs/heads/main
```
This means that the my local branch `main` is mapped to the remote repo called `origin` and is merged to the remote `main` branch.

We can have several remotes, with different remotes for push and pulls (fetch).

Now I can see [my source code on the project's GitHub page](https://github.com/ShulyAvraham/LIMS_results_validation).

### Correct the comment for my last commit **before push** 
My first commit 
```
git commit -m'some comment'
```
Let's look at the commit's sha
```
git log
```
Now change the comment for the last commit 
```
git commit -m'a different comment' --amend
```
See the the sha was modified 
```
git log
```

The next section will discuss [Testing for continuous integration](https://dev.to/shulyavraham/testing-for-ci-2d73)