- On your server:
- Install git as per the documentation related to your server
- Setup the default git user
- mkdir -p ~/.ssh && chmod 0700 ~/.ssh
- touch ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys
- Create the repository
- git init –bare ~/theNewGitRepositoryNameComesHere.git
- On your client (suppose you already have some code to push to the new repo):
- Add your public key to the /home/git/.ssh/authorized_keys file (created above) on the server
- git init
- git remote add origin git@yourServerNameComesHere.com:/home/git/theNewGitRepositoryNameComesHere.git
- git add .
- git commit -m ‘Initial commit’
- git push -u origin master
Category: git
How to create a hotfix
If you follow the Semantic Versioning notation when delivering your code it’s important to know the way to create a hotfix when needed. Here are the basic steps to follow in order to achieve it:
- Get the latest changes from your remote
- git fetch
- Checkout the version you would like to patch with the hotfix (ex.: “v1.2.3”)
- git checkout VERSION
- Create the hotfix branch for the related version. It should follow the semver convention (ex.: “v1.2.3-1”)
- git checkout -b hotfix/HOTFIXVERSION
- Do your modifications, cherry-pick, apply patches, etc.
- Commit your changes
- git add .
- git commit -m “fix: The commit message comes here”
- Push them to the remote
- git push -u origin hotfix/HOTFIXVERSION
- Tag the hotfix version and push
- git tag HOTFIXVERSION
- git push origin HOTFIXVERSION
Squashing multiple commits into one
In your daily tasks if you need to squash multiple commits into one with a custom message just perform the following commands:
git reset --soft HEAD~n # where n is the number of last commits you want to squash into one
git commit --amend
git push -f
another (interactive) way is to use rebase like below:
git rebase -i HEAD~n
the last n commit messages will appear in your text editor. You will see something similar to:
pick 0123456 Message 1
pick 1234567 Message 2
pick 2345678 Message 3
you could just pick the first commit and squash the rest like that:
p 0123456 Message 1
s 1234567 Message 2
s 2345678 Message 3