The best place to go to install Git on your computer depends on the operating system you are using. Here are some links to the official installation instructions for different platforms:
Windows: You can download the Git for Windows installer from the official Git website at https://git-scm.com/download/win
MacOS: You can install Git on MacOS using the Homebrew package manager, or you can download the Git for Mac installer from the official Git website at https://git-scm.com/download/mac
Linux: You can install Git on Linux using your distribution's package manager. For example, on Ubuntu, you can run the following command in the terminal to install Git:
tom@gold:~$ sudo apt-get install git
Regardless of the platform you're using, I recommend following the official installation instructions for the most up-to-date information and the best results.
If you run into any issues during the installation process, there are many online resources and forums where you can seek help and support.
The main website for Git is https://git-scm.com/. This website provides information about Git, including documentation, tutorials, and download links for various platforms. It is also the primary source for the Git software itself.
To install Git on Fedora, you can use the dnf command line tool, which is the package manager for Fedora. Here are the steps to install Git on Fedora:
Open the terminal by pressing Ctrl + Alt + T
Run the following command to update the package information:
tom@gold:~$ sudo dnf update
Run the following command to install Git:
tom@gold:~$ sudo dnf install git
Wait for the installation to complete. You can verify that Git is installed by running the following command:
tom@gold:~$ git --version
This will display the version number of Git that you have installed.
With these steps, you should now have Git installed on your Fedora system and be able to use it for version control. If you run into any issues or have any questions during the installation process, there are many online resources and forums where you can seek help and support.
WARNING: Before you execute any git commands below you need to make your current directory, the directory of the project that your intending to use git with. It is the directory containing the source-tree (the directory structure containing source code files).
tom@gold:~$ cd project-directory-path
To create a Git repository use the following command in the terminal:
tom@gold:~$ git init
The system responds;
int: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch &ls;name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m &ls;name>
Initialized empty Git repository in /home/user-name /project-directory-path /.git/
This command creates a new Git repository in the project-directory.
Before a commit command you need to add file or directory names to the "staging-area", a list of files and directories to be examined in the commit operation. For this you use the following commands:
tom@gold:~$ git add path
Replace
Now you can commit the file or directory changes to the repository.
A commit is an event in the history of the repository that saves the current state of the files. You can commit the changes using the following command:
tom@gold:~$ git commit -m "brief description"
It is useful to have a "brief description" of the changes you're committing.
ADVICE: It is worth doing a commit for any group of significant changes. Be careful as a global rename in multiple files can swamp other changes, so when doing drastic automated changes like these they should have their own commit to seperate them from more subtle human edits.
When you make a commit, Git creates a unique identifier (a hash value) for the commit and stores it in the repository along with a timestamp and your "brief description". The information about your name, computer name, and domain name is stored as part of your Git configuration.
If you want to view information about your commits, you can use the git log command. This command displays a history of the commits in the repository, including the hash value, author, date, and message for each commit:
tom@gold:~$ git log
This will show a list of all the commits in the repository, with the most recent commit first. You can use various options with the git log command to customize the output, such as limiting the number of commits displayed or showing more detailed information.
To display the details of a single commit - the commit message, author, date, and the changes made in the commit:
tom@gold:~$ git show hash value
There are several color options that you can configure for 'git show'. Here are a few examples:
These variables can be set to various colors and color codes, including color names (e.g. "yellow"), ANSI color codes (e.g. "1;31" for bright red), or hexadecimal color codes (e.g. "#FFA500" for orange, "#FF4444" for light red).
tom@gold:~$ git config --global color.diff.old "yellow"
tom@gold:~$ it config --global color.diff.old "#FF4444"
To compare the difference between two commits in Git, you can use the git diff command. Here is an example:
tom@gold:~$ git diff commit1 commit2
Replace
tom@gold:~$ git diff HEAD abc123
This will show you the difference between the two commits, including which lines were added or removed. To change the colours used see the heading 'Show changes' above.
If you want to see a more detailed diff with additional context, you can use the --patch option:
tom@gold:~$ git diff --patch commit1 commit2
This will show you a patch with the differences between the two commits. You can navigate through the patch using the arrow keys or the j and k keys to move up and down. Press q to exit the patch and return to the command prompt.
If you want to see the differences between two branches, you can use the same git diff command, but replace the commit IDs with the branch names. For example, to compare the difference between the master branch and the develop branch, you would use:
tom@gold:~$ git diff master develop
This will show you the difference between the two branches, including which lines were added or removed.
The git checkout command is used to switch between different branches or commits in a Git repository. When you use the git checkout command, you are telling Git to update the files in your source-tree to match the contents of a specific branch or commit.
To use the git checkout command, you first need to know the name or ID of the branch or commit you want to switch to. You can find this information using the git log command to view the history of your repository, or by checking the output of the git branch command to see a list of available branches.
Once you know the name or ID of the branch or commit you want to switch to, you can use the following command to check it out:
tom@gold:~$ git checkout branch or commit
For example, to switch to a branch called my-feature, you can use the following command:
tom@gold:~$ git checkout my-feature
To switch to a specific commit, you can use the ID or a reference to the commit, such as a tag or branch name. For example, to switch to a commit with the ID a1b2c3d, you can use the following command:
tom@gold:~$ git checkout a1b2c3d
When you use the git checkout command, Git will update the files in your source-tree to match the contents of the branch or commit you have checked out. This means that any changes you have made to the files will be overwritten, so it's important to commit or stash your changes before checking out a different branch or commit.
By default, when you check out a specific commit using the git checkout command, you will be in a "detached HEAD" state. This means that you are no longer on a named branch, but rather have checked out a specific commit directly. In this state, any changes you make to the files in your source-tree will not be associated with a branch, and will be lost if you check out a different commit.
If you want to keep the changes you make while in a detached HEAD state, you can create a new branch that points to the current commit by running the following command:
tom@gold:~$ git checkout -b new-branch-name
This will create a new branch that includes the changes you've made, allowing you to continue working from that point in your repository history.
It's worth noting that when you check out a specific commit, you may encounter "merge conflicts" if changes were made in that commit that conflict with changes made in subsequent commits. In this case, you may need to manually resolve the conflicts before continuing.
Committing changes and stashing changes are both ways to save changes in Git, but they serve different purposes.
Committing changes permanently records your changes to the repository history. This means that your changes become part of the permanent record of the project and can be seen by others who clone or pull the repository. When you commit changes, you typically include a commit message that describes the changes you made.
On the other hand, stashing changes is a way to temporarily save your changes without committing them. Stashing is useful when you're in the middle of working on a feature or bug fix, but need to switch to another task or branch. Stashing allows you to save your changes so that you can return to them later, but without committing them to the repository history. When you stash changes, Git saves a copy of your changes and reverts your source-tree to the state it was in before you made the changes.
Here's an example of how to stash changes in Git:
tom@gold:~$ git stash
This will save your changes and revert your source-tree to the last committed state. You can then switch to a different branch or task, and later return to your stashed changes by running:
tom@gold:~$ git stash apply
This will apply the changes you stashed and restore your source-tree to the state it was in when you stashed the changes.
In general, you should commit changes when you have completed a unit of work and are ready to share your changes with others. You should stash changes when you need to temporarily set aside your work to address another task or issue.
Branching in Git allows you to create a separate line of development for a specific feature or bug fix without affecting the main codebase. This can be very useful for collaborative projects or when working on a new feature that may take some time to complete. With Git, you can create a new branch based on the current commit, make changes to the code in the new branch, and then merge the changes back into the main branch once they are complete.
Merging in Git allows you to combine changes from one branch into another. When you merge two branches, Git automatically tries to combine the changes from both branches, but if there are conflicts (i.e., if changes were made to the same lines of code in both branches), Git will prompt you to resolve the conflicts before finalizing the merge.
Using Git branching and merging can be very powerful for managing complex development projects, enabling multiple developers to work on different features or bug fixes simultaneously without interfering with each other's work.
To create a new branch in Git, you can use the git branch command followed by the name of the new branch. For example, to create a new branch called new-feature, you can use the following command:
tom@gold:~$ git branch new-feature
This will create a new branch based on the current commit.
To switch to the new branch, you can use the git checkout command followed by the name of the branch. For example:
tom@gold:~$ git checkout new-feature
This will switch to the new new-feature branch, and any changes you make will now be recorded in that branch.
Alternatively, you can create a new branch and switch to it in a single step by using the git checkout command with the -b option, followed by the name of the new branch. For example:
tom@gold:~$ git checkout -b new-feature
This will create a new branch called new-feature and switch to it in one step.
Once you have created a new branch and made changes to the code in that branch, you can use the git merge command to merge the changes back into the main branch when you are ready. Tom de Havas How do I merge?
To merge changes from one branch into another, you can use the git merge command. Here's an example:
Suppose you have made changes in a branch called new-feature, and you want to merge those changes into the main branch (usually called master). First, switch to the master branch using the git checkout command:
tom@gold:~$ git checkout master
Then, use the git merge command followed by the name of the branch you want to merge (new-feature in this case):
tom@gold:~$ git merge new-feature
Git will automatically try to merge the changes from the new-feature branch into the master branch. If there are no conflicts between the two branches, Git will automatically apply the changes and create a new commit with a message indicating that a merge has occurred.
If there are conflicts between the two branches (i.e., if the same lines of code were modified in both branches), Git will prompt you to resolve the conflicts manually. You can do this by editing the files with conflicts, choosing which changes to keep, and then using the git add command to stage the changes. Once all conflicts have been resolved, you can use the git commit command to create a new commit with the merge changes.
After the merge is complete, you can delete the branch that you no longer need by using the git branch -d command followed by the name of the branch. For example:
tom@gold:~$ git branch -d new-feature
This will delete the new-feature branch.
There are many features in Git that we haven't covered yet, as Git is a very powerful and flexible tool. Here are a few additional features that you might find useful:
These are just a few examples of the many features available in Git. If you're interested in learning more, I would recommend exploring the Git documentation or a comprehensive Git tutorial.
Normally the directory of the repository often called .git is created by git init in what ever is current directory at the time. Subsequent git commands will always look for .git in the current directory at the time they are executed. If you have changed the current directory with a cd command for example, then they may not find the .git directory. It is a good practice that allows you to have multiple git repositories for multiple projects to change the current directory to the directory of the project your working on and so obtain access to the correct repository. However sometimes you would like to use a differently named repository on a different path.
To change the default Git directory, you can set the GIT_DIR environment variable to the path of your desired Git directory. This will tell Git to use that directory as the default Git directory for all Git commands.
Here's an example of how you can set the GIT_DIR environment variable on Linux or macOS:
tom@gold:~$ export GIT_DIR=directory-path
Once you've set the GIT_DIR environment variable, you can run Git commands as usual, and Git will use the specified directory as the default Git directory. You can see what it is set to at any time with the command:
tom@gold:~$ echo $GIT_DIR
Normally it will be blank which is interpreted by git as being the same as .git You can change this to be any path you desire including the path of USB devices.
Here's an example of resetting the GIT_DIR environment variable on Linux or macOS:
tom@gold:~$ export GIT_DIR=../myg.git
This looks one directory level up from the current directory for a git repository called myg.git
This section is under development as I have not yet used a remote repository.
If you want to share your code with others or access it from multiple computers, you can push the changes to a remote repository, such as GitHub or GitLab. You can do this using the following commands:
tom@gold:~$ git remote add origin remote repository URL
tom@gold:~$ git push -u origin master
Replace
If you want to work on a project that's hosted on a remote repository, you can clone the repository to your local machine. You can do this using the following command:
tom@gold:~$ git clone remote repository URL
Replace
These are the basic steps to start using Git for version control. As you continue to use Git, you'll learn more advanced features, such as branching and merging, that allow you to manage your projects more effectively.
This section is under development as I have not yet succeeded in making use of gitkraken as I did not want to read there extensive licensing terms. So this is all the info I have.
If you want to use Git as a standalone graphical application, you can install GitKraken, source-tree, or any other Git GUI client. These applications provide a graphical user interface for working with Git and make it easier to manage your Git repositories and work with your code.
GitKraken is a proprietary Git GUI client that offers a free version as well as paid versions with additional features. The cost of GitKraken depends on the version you choose and the number of users you have.
Here is an overview of the pricing for GitKraken:
Free version: The free version of GitKraken is available for personal use and includes basic features such as Git repository management, code commenting, and file browsing.
Individual Plan: The Individual Plan costs $4.08/month (billed annually) and includes additional features such as GitLab and GitHub integration, code commenting, and file browsing.
Pro Plan: The Pro Plan starts at $7.08/month (billed annually) per user and includes advanced features such as code review, merge conflict editor, and code commenting.
Teams Plan: The Teams Plan starts at $12.50/month (billed annually) per user and includes advanced collaboration features such as code review, merge conflict editor, and code commenting.
Please note that the pricing for GitKraken may change over time, so it's always a good idea to check the official GitKraken website for the most up-to-date pricing information.
You can install a Git GUI client on Fedora by using the dnf package manager:
tom@gold:~$ wget https://release.gitkraken.com/linux/gitkraken-amd64.rpm
tom@gold:~$ sudo dnf install ./gitkraken-amd64.rpm
GitKraken Client data is stored in the hidden directory /home/
which is the same as ~/.gitkraken
.
Some Linux distros do not automatically create shortcuts to the app. To run GitKraken Client manually, open the terminal and type;
tom@gold:~$ gitkraken
to start the app.
To install an RPM package in Fedora, you can use the dnf package manager. The dnf package manager is the default package manager in Fedora and is used to install, update, and manage software packages on the system.
Here are the steps to install an RPM package in Fedora using the dnf package manager:
Open the terminal by pressing Ctrl + Alt + T.
Download the RPM package to your system. You can download the RPM package either from a website or by using the wget command in the terminal.
Change to the directory where the RPM package is located. You can use the cd command in the terminal to change the current directory.
Install the RPM package by running the following command in the terminal:
tom@gold:~$ sudo dnf install RPMpackageName. rpm
Replace
Wait for the installation process to complete. The dnf package manager will download and install the RPM package, along with any required dependencies.
Once the installation is complete, you can start using the software package.
With these steps, you should now be able to install RPM packages in Fedora using the dnf package manager.