DEV Community

ShulyAvraham
ShulyAvraham

Posted on • Edited on

OSDC Lesson 4: My project on GitHub

Place my own project on GitHub

Enter my project's dir

cd <my-proj>
Enter fullscreen mode Exit fullscreen mode

Add the project to git and create the repository

git init
Enter fullscreen mode Exit fullscreen mode

a .git directory will be created

ls -l
Enter fullscreen mode Exit fullscreen mode

Check the status of the git

git status
Enter fullscreen mode Exit fullscreen mode

Add all files to the staging

git add .
Enter fullscreen mode Exit fullscreen mode

Remove a file which I don't want to track on git from staging (e.g. python's cache file)

git reset <file>
Enter fullscreen mode Exit fullscreen mode

OR

git rm --cached <file>
Enter fullscreen mode Exit fullscreen mode

git alias

Add the following to the ~/.gitconfig file.

[alias]
    st = status
    co = checkout
    ci = commit
Enter fullscreen mode Exit fullscreen mode

git ignore

Add to the .gitginore file a list of files or folders that you want git to ignore, e.g. __pycache___

vi .gitignore
Enter fullscreen mode Exit fullscreen mode

Add the .gitignore file to git

git add .gitignore
Enter fullscreen mode Exit fullscreen mode

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
  • 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
Enter fullscreen mode Exit fullscreen mode

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/*
Enter fullscreen mode Exit fullscreen mode

Map my branch to main

git branch -M main
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

This will add the following to the .git/config file

[branch "main"]
        remote = origin
        merge = refs/heads/main
Enter fullscreen mode Exit fullscreen mode

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.

Correct the comment for my last commit before push

My first commit

git commit -m'some comment'
Enter fullscreen mode Exit fullscreen mode

Let's look at the commit's sha

git log
Enter fullscreen mode Exit fullscreen mode

Now change the comment for the last commit

git commit -m'a different comment' --amend
Enter fullscreen mode Exit fullscreen mode

See the the sha was modified

git log
Enter fullscreen mode Exit fullscreen mode

The next section will discuss Testing for continuous integration

Top comments (0)