mkdir <<project name>>
cd <<project name>>
git init
choose namespace (aka group) and project name
be sure to have added and commit your files first
git push --set-upstream https://gitlab.example.com/namespace/myproject.git master
git clone <<repourl>>
git checkout master
git branch <<branch name>>
git checkout <<branch name>>
or all in one
git checkout -b <<branch name>>
we can create a branch from a given commit : git branch <<branche name>> <<commit id>>
or from a given tag : git branch <<branche name>> <<tag>>
add files to stage area first
git add <<filename>>
or git add --all
at the root of the project
then
git commit -m "<<commit message>>"
git branch
list also the remote
git branch -r
Store them on disk :
git config --global credential.helper store
next time you enter your credentials they will be cached
Store them for your current terminal session (more secure but less convenient)
git config --global credential.helper cache
git status
git remote show origin
git push -u origin <<branch name>>
TODO check if there is no easier method
make master uptodate
git fetch --all
git checkout master
git pull --rebase origin master
make master uptodate (see above)
switch to branch and rebase from master (branch commit will be appended)
git checkout <<branch name>>
git rebase master
make master uptodate (see above)
switch to branch and merge master into branch
git merge master
if merge failed, and is to hard to debunk
git merge --abort
to revert the merge
prune branch no longer on remote
git fetch --prune
or git remote prune
list branch no longer tracked
git branch --v | grep "\[gone\]"
delete branch one by one
git branch -D <<branch name>>
all in onegit branch --v | grep "\[gone\]" | awk '{print $1}' | xargs git branch -D
list files in conflict (shell only)
grep -lr '<<<<<<<' .
accepting theirs
git checkout --theirs <<filename>>
accepting mine
git checkout --ours <<filename>>
then add the files updated
git add <<filename>>
probably need to continue a rebase
git rebase --continue
or abort it
git rebase --abort
get all branch info from remote
git fetch --all
then reset to master
git reset --hard origin/master
or if for another branch
git reset --hard origin/<branch_name>
Annotated tag (an entry in history)
git tag -a <<tag name>> -m "<<tag message>>"
Ligthweight tag (just a pointer to a commit)
git tag <<tag name>>
To checkout a tag in a branch
git checkout tags/<tag> -b <branch>
git commit --amend
an editor open, change main message (lines starting with # will be ignored) save & close.
check everything is ok with git log
for a given branch
git checkout <<branch_name>>
git pull <<branch_name>>
git log <<branch_name>> --no-merges --since="6 day ago"
git branch -m <oldname> <newname>
on wrong branch_name
git reset HEAD~1
then go to new branch
then add and commit
for a local repo
first create on Gitlab an empty project
cd in the directory
then
git init
git remote add origin {here you git url}
git add .
git commit -m "Initial commit"
git push -u origin master`
for a remote repo see : https://superuser.com/questions/1412078/bring-a-local-folder-to-remote-git-repo/1412081
create a personnal access token with api access (in gitlab : 'user settings > access tokens') get groupId in web portal (in gitlab it is disaplyed below group name) in bash (with jq installed) :
TOKEN="yourtoken"
for repo in $(curl -s --header "PRIVATE-TOKEN: $TOKEN" https://<your-host>/api/v4/groups/<group_id> | jq -r ".projects[].ssh_url_to_repo"); do git clone $repo; done;
To include subgroups add include_subgroups=true query param like To request clone with http url use : http_url_to_repo instead of ssh_url_to_repo