# Git intro First thing to do is to setup your identity. This identifies you to other people who download the project. ``` $ git config --global user.name "Your Name" $ git config --global user.email your.email@example.com ``` Because we are using ssh do the following steps: 1. Open a terminal 2. Go to your home directory by typing cd ~/ 3. Type the following command ssh-keygen -t rsa 4. This will prompt you to enter a filename to store the key 5. Just press enter to accept the default filename (/Users/you/.ssh/id_rsa) 6. Then it will ask you to create a passphrase. This is optional, either create a passphrase or press enter for no passphrase 7. When you press enter, two files will be created * ~/.ssh/id_rsa * ~/.ssh/id_rsa.pub 8. Your public key is stored in the file ending with .pub, i.e.: * ``` ~/.ssh/id_rsa.pub``` 9. Copy the ssh ```pbcopy < ~/.ssh/id_rsa.pub``` 10. Once you have copied your public SSH key, login to your GitHub account and go to https://github.com/settings/profile 11. On the left-hand side menu, you will see a link “SSH and GPG keys” 12. Click on that link which will take you to a page where you can enter your public SSH key that you copied earlier. 13. Click the button which says ‘New SSH key’ 14. Then enter a title name - can be anything, e.g. newMac 15. Paste the public SSH key in the key textbox 16. Click “Add SSH key” Clone the repo: ``` git clone git@github.com:LinumLabs/github-workshop.git ``` Create a branch ``` git checkout -b my-branch ``` in Linum we use this convention of branch names ``` feature/mm/ticket-number fix/mm/ticket-number ``` Add files: ``` touch bob.txt alice.txt ``` Add files to git: ``` git add . ``` Add commit message: ``` git commit -m "Commit message" ``` Push: ``` git push ``` Pull: ``` git pull ``` Create new origin: If forking is not a option and you need to import other project lets say like a boilerplate ``` git remote add web3 git@github.com:LinumLabs/web3-task.git ``` Pull from other remote: ``` git pull web3 master ``` If you are working on some project specific and want to push some changes to remote ``` git push web3 ``` It will create same branch name with same changes that you made If you are working on wrong branch and need to checkout with current changes ``` git stash --include-untracked ``` Create or change branch ``` git checkout branch-name ``` Create new: ``` git checkout -b branch-name ``` Apply latest stash ``` git stash pop ``` For these steps I would recommend using VSCode and do it through UI. Differences between git stash apply and git pop: * git pop: ‘pops’ the changes from the stash and applies them to the current code * git stash apply: keeps the changes in the stash and applies the changes to the current code If something happens with merge of remote branch: ``` git pull origin branchname --allow-unrelated-histories ```