Git: Difference between revisions
Jump to navigation
Jump to search
Line 53: | Line 53: | ||
root@perth:/etc# grep git /etc/shadow | root@perth:/etc# grep git /etc/shadow | ||
git:*:17767:0:99999:7::: | git:*:17767:0:99999:7::: | ||
</pre> | |||
<pre> | |||
root@perth:/opt/git-server/bin# cat refresh-auth | |||
#!/bin/bash | |||
GIT_SERVER_DIR=/opt/git-server | |||
KEY_DIR=$GIT_SERVER_DIR/keys | |||
SSH_KEY_FILE=$GIT_SERVER_DIR/repos/.ssh/authorized_keys | |||
SSH_KEY_PREFIX="no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding" | |||
find $KEY_DIR -type f -exec grep -v '#' {} \; | awk '$1' | sort -u | sed -e "s/^/${SSH_KEY_PREFIX} /" > $SSH_KEY_FILE | |||
</pre> | </pre> | ||
Revision as of 23:39, 5 January 2024
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:::
root@perth:/opt/git-server/bin# cat refresh-auth #!/bin/bash GIT_SERVER_DIR=/opt/git-server KEY_DIR=$GIT_SERVER_DIR/keys SSH_KEY_FILE=$GIT_SERVER_DIR/repos/.ssh/authorized_keys SSH_KEY_PREFIX="no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding" find $KEY_DIR -type f -exec grep -v '#' {} \; | awk '$1' | sort -u | sed -e "s/^/${SSH_KEY_PREFIX} /" > $SSH_KEY_FILE
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