In order to use git
- Check git version
- Command: git -version
- If not install, add it to your server (Centos)
- sudo yum install git-all
- Create local Repository:
- Command: git init
- Add all file to your local git
- command: git add -u *
- Commit them to your local repository
- command git commit <file> -m “some comment”
- Check the status of your git:
- command: git status
- Check all logs
- command: git log
- Check diff
- command:git diff <file name>
- Check your branch:
- command: git branch
- Create Gitlab account and then create new project.
- Create key to connect to ssh (on your server
- ssh-keygen -t rsa -C “[email protected]”
- Add ssh key to your server (Ensure the ssh-agent is running)
- command: eval(ssh-agent -s) or eval
ssh-agent -s
– This execute bash script, you need re-run everytime server restarted
- command: eval(ssh-agent -s) or eval
- Add your SSH key to the ssh-agent
- Command: ssh-add id_rsa (full path: ssh-add /root/.ssh/id_rsa)
- Check if ssh added fully (should return 0)
- Command: ssh-add -l
- Copy the value of public key
- command: cat /root/.ssh/id_rsa.pub
- On gitlab, select your project, click setting and click deploy key then paste the value of your public key
- Copy ssh link of your project.
- Add remote project to your server
- command:git remote add remoteName project_ssh_link (without ssh)
- If you added wrongly, update site url
- command: git remote set-url remoteName /the/correct/url
- Check all remote links:
- command: git remote -v
- Push to your remote
- Command: git push -u remoteName master
- Get latest changes from remote:
- Command: git fetch remoteName
- Get latest changes from remote and merge:
- Command: git pull remoteName
- Remove remote git on server
- Command: git remote rm destination
Some more tips
Add your file to .gitignore if you dont want to git index them
If the agent has no identities after adding key add key again
chmod for id_rs key should be 600
Increase the Git buffer size to the largest individual file size (for upload via http):
git config –global http.postBuffer 157286400 (for 1.5 GB)
check remote branches:
git branch -r
move to remote branches:
git checkout –track origin/branch
shorthand for:
git checkout -b [branch] [remotename]/[branch]