Git: the beginner’s guide

Git is a collection of console tools that track and record changes in the files (usually, it is related to the source code of the applications, but you can use it for any other files of your choice). 

Why do you need Git?

1. Makes working on one project easier for several people;

2. Easy to track mistakes;

3. Easy to cancel any changes;

4. Save changes (who, when, and what was done);

5. Difficult to lose files with a source code;

Installing Git

Installing on Linux on base ubuntu.

sudo apt-get install git

Installing on Windows — git for windows is recommended because it contains the client with the graphical interface and bash emulator. 

Download git for Windows.

Settings

Before start working, you need to apply certain settings. 

# indicate name which will be used to describe commits
git config –global user.name “Your Name”
# indicate mail which will be in the description of a committer
git config –global user.email “email@gmail.com”

Creating new repository

To create new Git repository, you need to open a folder where you want to place and execute the command:

#Creation of new repository
git init

How to clone the existing Git repository to local

Important!!! During copying from Git, it will create the folder for the repository.

#open in terminal a folder with the projects
cd ~/git-dev/
#Clone the existing repository
git clone ssh://user@domain.com/repo.git

Commands for working  with project that is already in local space

1. Open folder with the repository.

cd ~/git-dev/test-project

2. Make needed changes

3. Add files to the index

#will add all files with the changes.
git add.
—————————-
#add certain
git add sections/home-custom.liquid
git add assets/theme.scss
git add assets/theme.scss.liquid

4. Make commit

git commit -m “Add you text commit”

5. For the convenience, you can add the version mark (any option):

git tag v1.0

6. Sending changes to Git server

Git push

7. Now you need to update tags.

Important! Update tags only if you have assigned them.

git push –tags

Working with branches

1. What branch are you on now?

git branch

2. Creating new branch

git branch you_name

3. Transition to branch: you_name:

git checkout you_name

Useful commands

# pull changes from the remote repository to local (only branch master-development)
git pull origin master-development
#review the history of commits
git log
#checking all the settings
git config –list
#get to know the name that will be used for commits
git config –global user.name
#get to know the mail that will be in the description of the committer
git config –global user.email
#Check the status of the files in index:
git status
#will add all files
git add.

#add certain files
git add assets/theme1.scss
git add assets/theme2.scss

Related Articles

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments