Basic Git commands

Cloning a Repository

To clone a repository into a subfolder of your current directory (Eg if you are in /git the repository will be cloned to /git/[repository name]) run the below:

git clone [email protected]:project/repository.git

Cloning a Repository to a specific directory

To clone a repository into a specific directory (Eg /git/example in the below) run the below:

git clone [email protected]:project/repository.git /git/example

Checking out an alternative branch

Once you have cloned the repository, browse into the directory (using the directory /git/example and branch ‘alt’ in the example below) run the following:

cd /git/example
git checkout alt

Listing modified files

To confirm which files you have edited before committing your changes, run the below command:

git status

Committing your changes for review

When you have completed your work, you must now commit your changes back to Gitlab.

Individual files

The below example will only add the individual files that you have worked on:

git add example/install.sh
git add directory/example.sh
git commit -m "An appropriate name for your changes"
git push

All files

The below example will re-commit all new / changed files within the repository on your machine:

git add -A
git commit -m "An appropriate name for your changes"
git push

Any comments or questions? Get in touch here or Email me at [email protected]