Git

From Wiki
Revision as of 23:36, 5 January 2024 by Scott (talk | contribs) (Cheat Sheets)
Jump to navigation Jump to search

Initial Setup

git config --global user.name "Harry Truman"
git config --global user.email "harry.truman@example.com"
git config --global --list

May need to set up SSH-key authentication for gitlab.

Clone Repository

git clone git@gitlab.com:scottcamacmartin/my_project.git

Upload Existing Code Directory as Gitlab Repository

First, creat a new project on gitlab. Then, on the local dev machine:

git clone git@gitlab.com:scottcamacmartin/my_project.git
cd my_project
# then copy code into new folder my_project
# DELETE ANY SENSITIVE PASSWORDS, ETC
# also set up .gitignore file
git status
git add .
git commit -m "initial commit"
git push -u origin master

Overwrite local from repository

git fetch --all
git reset --hard origin/master

Cheat Sheets

https://about.gitlab.com/images/press/git-cheat-sheet.pdf

https://github.com/kenmueller/gitignore


Git Server

https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

/opt/git-server/bin         # refresh-auth command
/opt/git-server/keys        # ssh keys
/opt/git-server/repos       # home directory with repos
/opt/git-server/repos/.ssh  # authorized_users file
root@perth:/etc# grep git /etc/passwd
git:x:222:222:Git Service User:/opt/git-server/repos:/usr/bin/git-shell
root@perth:/etc# grep git /etc/group
git:x:222:
root@perth:/etc# grep git /etc/shadow
git:*:17767:0:99999:7:::

Initialize repository

As root on git server:

cd ~git
mkdir project.git
cd project.git
git init --bare
cd ..
chown -R git.git project.git

As developer on developer PC:

cd project
emacs .gitignore  # include a line with "**/.hg" to exclude .hg content
git init
git add .
git commit -m 'Initial commit'
git remote add origin git@irc-git-host:project.git
git push origin master

As another user:

git clone git@irc-git-host:project.git