It’s very important to add an SSH key to GitLab to work on a remote project what is hosted on GitLab. Let see how we can do that –
We working on a Mac to set up this key –
1. Go to your terminal and write the command below –
ssh-keygen -t rsa -C "[email protected]"
Press Enter (to make a file with the default name)
Type ‘y’ (to overwrite
Press Enter (to skip passphrase)
2. To see the generated key type :
Copy the key and paste it to your GitLab profile.
Now start pull / push / clone etc. commands.
It’s very convenient to use an alias instead of full command. So, let’s see how we can make some aliases for git command –
To make an alias, open the terminal and write the command below –
Write some aliases –
alias gs=”git status”
alias ga=”git add”
alias gm=”git commit -m”
alias bci=”brew cask install”
Colse and save the vim with clicking esc button and :wq
To make your created aliases work, run the command below –
Done. Now you can use the aliases you made as many times as you want.
Suppose we have created a dev branch from the master branch and then the dev branch has got some new commits. So, now we want to keep only the dev branch’s codes in master branch except all the old codes from the master. Let see how we can do that –
Make sure that your local master is up to date with the master remote:
git checkout master git fetch origin git pull
Goto to Project directory through the command:
git add .
git commit -m "your message"
Go to the directory you want to initiate Git and then follow the commands:
- Initiate the git:
- Remove Git if you have initiated in a wrong place ( Be aware if there is another git in the subdirectory):
rm -rf .git
- To add all the files(including subdirectory) to the staging step:
git add .Or,
git add -A
- Git branch –
a. Create a new one from the current branch and Checkout to the new branch:
git checkout -b newBranchb. Delete a branch branch:
git branch -d branchName
- Merge master to development branch –
1. //pull the latest changes of current development branch if any
git pull (current development branch)
2. //switch to master branch
git checkout master
3. //pull all the changes if any
4. //Now merge development into master
git merge develop
5. //push the master branch
git push origin master