Skip to content

GIT Guide

Init git

$ git init

Git flow init

$ git flow init

I use master and develop branches!

Git submodules (helper)

Add submodule

git submodule add https://github.com/socketio/socket.io-client-cpp.git external/socket.io-client-cpp

git submodule add https://github.com/pnggroup/libpng.git external/libpng

git submodule add <remote_url> <destination_folder>

git commit -m "Added the submodule to the project."

git push

A hidden file named .gitmodules is created in your Git repository; this file contains the references to the remote repositories that you cloned as submodules.

Pull a git submodule

If you don’t execute this command, you will fetch the submodule folder, but you won’t have any content in it.

To pull a Git submodule, use the git submodule update command with the –init and the –recursive options.

git submodule update --init --recursive

Update a git submodule

In some cases, you are not pulling a Git submodule but you are simply look to update your existing Git submodule in the project.

In order to update an existing Git submodule, you need to execute the git submodule update with the –remote and the –merge option.

git submodule update --remote --merge

Remove a submodule

git rm external/live555helper

Remove the submodule directory from the superproject's .git/modules directory

rm -rf .git/modules/external/live555helper

Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule.

git rm -f .git/modules/external/live555helper

Git origins

See remotes

git remote -v

Add origin

git remote add origin https://github.com/user/repo.git

Set/change origin

git remote set-url origin https://github.com/user/repo2.git

Git tags

Create a git tag from a commit

git tag -a <tag_name> 9fceb02 -m "Message here"

Show all tags

git tag

git tag -l <pattern>

git tag --sort=<type>

Push single tag

git push origin <tag_name>

Push all tags

git push --tags

Get remote tags

git ls-remote --tags origin

Delete remote tag

git push --delete origin <tag_name>

.gitconfig file

In case you have access token you can use it automatically in this file. See below:

[credential "https://..."]
    helper = "!f() { \
        echo 'username=name@domain.com' ; \
        echo 'password=<access-token;glpat-... in gitlab>' ; \
    }; f"
[user]
    email = name@domain.com
    name = Your Name