2. Sharing our repository

  • Git has 3 major platforms for code sharing:
    1. Github (http://www.github.com)
    2. Bitbucket (http://www.bitbucket.com)
    3. Gitlab (http://www.gitlab.com)

We are going to use Github since its a free and easy to use platform, but any Git based platform would work in the exact same way

Step 1: Create a github/bitbucket/gitlab account

Step 2: Create a repository See Here an Example

Step 3: Get your repository URL

How to Share? The GIT REMOTE, PUSH, PULL and CLONE commands

GIT REMOTE and PUSH

  • Adding our remote server with the REMOTE command. We refer to this server as "Origin", you could use any name though
!git remote add origin https://github.com/rafaelpossas/git_tutorial.git
  • Showing our current remote repositories
!git remote -v # Show remote repositories
origin  https://github.com/rafaelpossas/git_tutorial.git (fetch)
origin  https://github.com/rafaelpossas/git_tutorial.git (push)
  • Pushing our files/changes to our remote repository
!git status
On branch master
nothing to commit, working tree clean
!git push -u origin master
 Counting objects: 4, done.
 Delta compression using up to 8 threads.
 Compressing objects: 100% (3/3), done.
 Writing objects: 100% (4/4), 386 bytes | 0 bytes/s, done.
 Total 4 (delta 0), reused 0 (delta 0)
 To https://github.com/rafaelpossas/git_tutorial.git
  * [new branch]      master -> master
 Branch master set up to track remote branch master from origin.

We have pushed all our files along with our git history tracking to a remote repository, note that we pushed our changes to the 'master' branch, branches will be explained later

Usually on GIT the main branch is called master and the remote server is called origin

  • Removing our repository
!rm -rf git_tutorial
!cd ..
!ls
GIT_TUTORIAL.txt README.txt
  • Cloning from the remote repository we've just pushed our files
!git clone https://github.com/rafaelpossas/git_tutorial.git
fatal: destination path 'git_tutorial' already exists and is not an empty directory.
cd git_tutorial
/Users/rafaelpossas/git_tutorial/git_tutorial/git_tutorial
!ls
GIT_TUTORIAL.txt README.txt

All our files were restored to the state of our last commit

GIT General Workflow overview