Git

 

 

References:

git.impa.br
http://rogerdudler.github.io/git-guide/
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-gitlab-on-ubuntu-16-04

 

Git global setup

git config --global user.name "Guilherme Tegoni Goedert"
git config --global user.email "ggoedert@impa.br"
 

Adding an SSH Key to your Account

[credit to DigitalOcean]

In most cases, you will want to use SSH keys with Git to interact with your GitLab projects. To do this, you need to add your SSH public key to your GitLab account.

If you already have an SSH key pair created on your local computer, you can usually view the public key by typing:

cat ~/.ssh/id_rsa.pub

 

You should see a large chunk of text, like this:

Output

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMuyMtMl6aWwqBCvQx7YXvZd7bCFVDsyln3yh5/8Pu23LW88VXfJgsBvhZZ9W0rPBGYyzE/TDzwwITvVQcKrwQrvQlYxTVbqZQDlmsC41HnwDfGFXg+QouZemQ2YgMeHfBzy+w26/gg480nC2PPNd0OG79+e7gFVrTL79JA/MyePBugvYqOAbl30h7M1a7EHP3IV5DQUQg4YUq49v4d3AvM0aia4EUowJs0P/j83nsZt8yiE2JEYR03kDgT/qziPK7LnVFqpFDSPC3MR3b8B354E9Af4C/JHgvglv2tsxOyvKupyZonbyr68CqSorO2rAwY/jWFEiArIaVuDiR9YM5 sammy@mydesktop 

Copy this text and head back to the Profile Settings page in GitLab's web interface.

If, instead, you get a message that looks like this, you do not yet have an SSH key pair configured on your machine:

Output

cat: /home/sammy/.ssh/id_rsa.pub: No such file or directory

If this is the case, you can create an SSH key pair by typing:

ssh-keygen

Accept the defaults and optionally provide a password to secure the key locally:

Output

Generating public/private rsa key pair. Enter file in which to save the key (/home/sammy/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/sammy/.ssh/id_rsa. Your public key has been saved in /home/sammy/.ssh/id_rsa.pub. The key fingerprint is: SHA256:I8v5/M5xOicZRZq/XRcSBNxTQV2BZszjlWaIHi5chc0 sammy@gitlab.docsthat.work The key's randomart image is: +---[RSA 2048]----+ | ..%o==B| | *.E =.| | . ++= B | | ooo.o . | | . S .o . .| | . + .. . o| | + .o.o ..| | o .++o . | | oo=+ | +----[SHA256]-----+

Once you have this, you can display your public key as above by typing:

cat ~/.ssh/id_rsa.pub

Output

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMuyMtMl6aWwqBCvQx7YXvZd7bCFVDsyln3yh5/8Pu23LW88VXfJgsBvhZZ9W0rPBGYyzE/TDzwwITvVQcKrwQrvQlYxTVbqZQDlmsC41HnwDfGFXg+QouZemQ2YgMeHfBzy+w26/gg480nC2PPNd0OG79+e7gFVrTL79JA/MyePBugvYqOAbl30h7M1a7EHP3IV5DQUQg4YUq49v4d3AvM0aia4EUowJs0P/j83nsZt8yiE2JEYR03kDgT/qziPK7LnVFqpFDSPC3MR3b8B354E9Af4C/JHgvglv2tsxOyvKupyZonbyr68CqSorO2rAwY/jWFEiArIaVuDiR9YM5 sammy@mydesktop

Copy the block of text that's displayed and head back to your Profile Settings in GitLab's web interface.

Click on the SSH Keys item in the left-hand menu:

GitLab SSH Keys menu item

In the provided space paste the public key you copied from your local machine. Give it a descriptive title, and click the Add key button:

GitLab add SSH Key

You should now be able to manage your GitLab projects and repositories from your local machine without having to provide your GitLab account credentials.


 

Create a new repository or use an existing one

Create a new repository

git clone git@<GIT_ADDRESS>:<USER>/<Repository_Name>.git
cd EDO

Existing folder or Git repository

cd existing_folder
git init
git remote add origin git@<GIT_ADDRESS>:<USER>/<Repository_Name>.git
git add .
git commit
git push -u origin master

 

 

Commands for Daily use

Show repository and status

git status

 

Add a file or repository in your current pc directory to your git tree

git add <Name of file/directory>

 

Add all files/directories in current directory to the git tree

git add .

 

Confirm (commit) changes to your git tree and save this version of the tree

git commit

Useful options to this command

                  -a    add all files to commit

                  -m  "<your message here>" 

 

Synchronization with online repository

Push your version to the online repository

git push origin master

 

Pull the online version to your local repository

git pull