FPC git
Git setup
The Git repository is hosted on Gitlab:
The URL to clone the repository is:
Windows Git clients
On macOS, Linux & BSD, the git command is installed with the system package manager (you must install XCode command line tools on macOS). On Windows, a separate git client must be installed. There are many available, but the following are popular ones:
- Git for windows: a command-line client with a bash shell, so you can copy & paste commands you find on internet:
- TortoiseGit integrates with the Windows explorer, much like TortoiseSVN does:
- Sourcetree is a free client for Windows and MacOS:
- https://www.sourcetreeapp.com/
- It is made by the people from bitbucket.
- Sourcetree is a free client for Windows:
- https://www.sourcetreeapp.com/
- It is made by the people from bitbucket.
- Smartgit runs on Windows, Linux and MacOS:
- The VSCode and Atom editors have git support built in.
Common SVN operations in Git
Check out
To check out a new copy of a repository is called 'cloning' in git.
git clone https://gitlab.com/freepascal.org/testconversion
As in subversion, you can give it another name:
git clone https://gitlab.com/freepascal.org/testconversion myconversion
This operation can take a while, the FPC source base is large.
Update
To update your source code with the changes in the remote repository, is called 'pulling' in git:
git pull
Note that in difference with subversion, git always updates the whole repository.
revert
If you have made some changes locally and wish to undo them, you can do a 'reset' in git:
git reset --hard
This will undo any changes you made. The above assumes you didn't do any git add.
commit
If you have made some changes locally and wish to commit them, this is a 2-step process:
git add myfile.pas
This schedules the file to be committed (called staging in git). You can add as many files as you want like this.
When you are ready to commit what you have staged, you can commit:
git commit -m '* Some nice comment telling what you did'
In fact, if you're in a hurry and know you want to commit a file, you can combine the 2 commands;
git commit -m '* Some nice comment telling what you did' myfile.pas
If you are really in a hurry, you can commit all changed files in one fell swoop:
git commit -m '* Some nice comment telling what you did' -a
But it is not really recommended to use this, as it will push all changes in your local copy, not just the ones in the current working directory.
At this point, your changes have been saved locally, but have not yet been sent to the remote repository. To do that, you must additionally send the changes to the remote repository. This is called pushing:
git push
copy (creating a branch)
To create a branch from the current working directory situation, you can create a branch like this:
git branch mybugfix
this will create a branch mybugfix from the current branch at the current commit. But it does not yet make this the active branch.
You need to check out the newly made branch first:
git checkout mybugfix
Again, the two operations can be performed in 1 command:
git checkout -b mybugfix
switch (checking out a branch)
To switch to an existing local branch `mybugfix`, you can use the checkout command:
git checkout mybugfix
this will check out branch mybugfix. If there are any uncommitted changes which would cause a conflict, git will refuse the checkout.
To switch to a remote branch `mybugfix2`, which does not exist yet locally, you can also use the checkout command:
git checkout mybugfix2
this will check out branch mybugfix2 and automatically set it up to track the remote branch. Here again, if there are any uncommitted changes which would cause a conflict, git will refuse the checkout.
Note that if the branch does not exist remotely, this will simply create a new branch locally. It is better to be explicit:
git checkout -b mybugfix2 --track origin/mybugfix2
If you created a branch locally which does not yet exist on the server, made some modifications, and you wish to push this branch to the server, you must tell this to git when pushing:
git push -u origin/mybugfix mybugfix
the -u origin/mybugfix tells git all it needs to know to connect the local with the remote branch.
merge (merging the changes in 2 branches)
To merge changes in 2 branches, you use the merge command. If we want to merge the changes in mybugfix to fixes then we do:
git checkout fixes git merge mybugfix