Using Git with Servers

Git Servers

• A git server can exist in several forms using: git protocol, HTTP, and SSH access to the remote git repo like Github, Stash from Atlassian, Bitbucket and Gitlab


Create a Remote Repository

On GitHub:
• Find the "New repository" button
• Provide a name and description of your repo
• Do not initialize the repo with a README (if you do, we can add an extra argument in one of the later commands.)
• Click the "Create repository" button

On local repository:
cd to local repo directory
• Copy and paste the following commands into CLI

# Push codes from local repo to remote repo
git remote add origin<your_username>/<your_repo>.git
git push -u origin master

• Replace URI with the one copied from Github
origin is just an alias for the remote server
master is the name of the branch into which you are pushing to remote repo

# To view the remote repo URI
git remote -v

• Setup SSH connection with remote repo
◇ Create SSH key and public key added to remote repository (see here)


Stage, Commit, Push, Pull

• The working cycle with remote repo will be as follow:
◇ Work on your code
◇ Stage & Commit your changes: git add <files> && git commit -m <your message>
◇ Push your changes: git push origin master
◇ If others are working on the same project, you will want to pull changes from the server.
◇ Pulling looks like git pull origin master