Warning: number_format() expects parameter 1 to be float, string given in /data/web/virtuals/7298/virtual/www/domains/kepty.cz/wp-includes/functions.php on line 423

7 git commands you should know

by May 20, 2023AL Language

Home 9 Development 9 AL Language 9 7 git commands you should know ( Page )

For many years, developers in C/AL did not need to know anything about Git or other versioning tools. That has changed with Business Central, or more specifically with AL Language. Today, we will look at the most important (and basic) git commands any developer should know.

These commands are usually quicker and more professional than working with the GIT UI in VS Code.

I’m not trying to explain how the git works, what can be done or how to master the git. This article is mainly for new developers in AL Language or developers who are experienced in C/AL development but do not know how to work with git commands in AL Language. For this reason, I tried to explain some parts in a straightforward way or even provide not completely accurate information, as these details/knowledge are not necessary for people who are not used to git.

> # Init new repository. Be sure you are in the right folder...
> cd /MyFolder/TheRealFolderIWantToUse/
> git init
>
> # Add all files and create the first commit with message "Init Commit"
> git add *
> git commit -m "Init commit"
> 
> # Link the local repository with the remote one in DevOps (similar code will be for GitHub)
> # You do not need to remember these two lines, they are always suggested by DevOps when you create a new repo
> git remote add origin https://ORGANIZATION@dev.azure.com/ORGANIZATION/PROJECT/_git/REPOSITORY
> git push -u origin --all
>
> # Add all .al files and create another commit
> git add *.al
> git commit -m "Another commit"
>
> # Add new changes to the previous commit (must be only local, not yet pushed to remote repository!)
> git add *.al
> git commit --amend
> # VS Code will open window with the overview of the commit, you can adjust the commit message or just close the window
> 
> # Check remote repository for any changes made by other developers
> git pull
>
> # Push local changes to remote repository
> git push
> 
> # Create a new branch
> git checkout -b "NewBranch"
>
> # Go to already existing branch
> git checkout main
>
> # Merge changes in main branch to NewBranch 
> git checkout "NewBranch"
> git merge main

And now, let’s explore each of these commands.

git init

The basic command to initialize a new repository. There is nothing special about this command; just be sure that you are in the folder you want to initialize (usually the parent folder of App/Test app folders).

git add

Another basic command that specifies which files/changes should be staged. You can use wildcards (*) to specify more than one file (for example, *.al specifies all .al files)

> git add .
> git add *
> git add *.al
> git add FileName.Table.al

git commit

Commit is the command you will be using most of the time. This command commits all the staged changes (added to the staged list using the add command). It’s always a good idea to provide an informative message (using the -m parameter).

I you need to update the last commit message or add new files/changes to the last commit, you can use the –amend parameter. This command will open a file with information about the last commit where you can update the commit message, and it will also automatically add all staged changes to this commit.

> git commit -m "Init commit"
> git commit -m "Another commit"
> git commit --amend

git pull

This command checks the remote repository for any new changes, and if there are changes, they will be downloaded and merged automatically to your local repository. It’s a bit more complicated, but for the purpose of this article, this should be well enough. There is a similar command, git fetch, but again, as this article is for beginners, you should be fine with the git pull only.

git push

This is the opposite command to git pull – it pushes your locally committed changes to the remote repository.

git checkout

Branches – the core of the versioning. I’ll publish another article in a few weeks about how to handle branch management and how to work with multiple branches. For now, just two basic commands

Git checkout changes your current branch to the branch you provide as a parameter. There is also a parameter (-b) that specifies that the branch does not exist yet and should be created. Without this parameter, if the branch does not exist, the command will end with an error.

> git checkout -b "NewBranch"
> git checkout main
> git checkout "NewBranch"

git merge

Git merge is the basic command you need to know when you are working with branches. It merges all changes from one repository to your current repository; for example, if other developers merged their changes to the main branch, you pull the changes to the main branch, checkout to your branch and using the git merge command, you can merge the changes in main to your branch.

If there are any conflicts that can’t be resolved automatically, VS Code will show you the UI editor, and it will be up to you to decide how the changes should be merged.

Recent Articles from the category

Collectible Errors?! Is it already in use?

Collectible Errors?! Is it already in use?

Collectible Errors?! Is it already in use? This is the second part of my new article series about Collectible Errors. Let's check out the first part here: Collectible Errors?! | Microsoft Dynamics 365 - Ing. Tomáš Kapitán (kepty.cz) or you might be interested in my...

read more
Collectible Errors?!

Collectible Errors?!

Collectible Errors?! It has been already almost a year since ErrorInfo datatype & CollectibleErrors were introduced (I already have an article about basic structure: ErrorInfo data type & Collectible Errors). This article was released for the first time in...

read more
Substituting standard reports

Substituting standard reports

Report objects cannot be extended in versions previous to the Business Central 2021 release wave 1 version when ReportExtensions object was introduced. Since then, many of changes we need to do in reports can be done without creating a new copy of object. On the other...

read more
Isolated events

Isolated events

With Business Central 2022 wave 1, a new setting for event publishers was introduced. Until this version, any error in any event subscriber caused interruption to the current running process and stopped the whole activity. In some cases (such as log-in), this is...

read more
Custom Filter Tokens

Custom Filter Tokens

As a user of the Business Central you have some constants you can use to filter or insert values. These constants contain useful values for data manipulation such as t / today for date field - return current dateq / quarter for date field filters - return range of the...

read more
1D & 2D Barcodes in Business Central 19.1

1D & 2D Barcodes in Business Central 19.1

Business Central (cloud-only!) includes one-dimensional (1D) barcode fonts since Microsoft Dynamics 365 Business Central 2020 wave 2 (17.0) was released in October 2020. It is a great improvement to how developers can handle requirements from their clients to print...

read more
How to let users choose field(s) properly

How to let users choose field(s) properly

When some complex functionality is developed, it is sometimes necessary to let users choose a specific field. This can be required for field permissions, mapping imported values or any similar process. Earlier, the usual way was to create a link on the Field table...

read more
Working with Translation Files (XLIFF)

Working with Translation Files (XLIFF)

How does the translation file work? In Microsoft Dynamic 365 Business Central, displaying different languages is done using the XLIFF files extension (.xlf). The generated XLIFF files have strings that are specified in properties like Captions, Tooltips......

read more
ErrorInfo data type & Collectible Errors

ErrorInfo data type & Collectible Errors

A major change to AL Language development is here! Collectible errors can hugely improve any validation procedures. And what's new? Everything is about a new data type ErrorInfo. ErrorInfo data type ErrorInfo is a new data type introduced in Microsoft Dynamics 365...

read more

Sign Up for News

Certifications

Highest certification
Microsoft Data Management and
also in D365 Business Central

Microsoft Certified: Dynamics 365 Business Central Functional Consultant Associate

See other certifications here