Setting up Git for the first time on a new project
Setting up Git for the first time on a new project is fairly simple, you just need to enter these five commands into your terminal. Be sure to be sitting in the directory where your project is located! You only need to do this once, right when you start your new project.
If you create a completely new project, you’ll have to go through these commands again. But only once per project.
Step 1: Run the following 5 commands using cmd or Git Bash (I used Git Bash)
$ git config --global user.name "Your Name"
$ git config --global user.email "you@youraddress.com"
$ git config --global push.default matching
$ git config --global alias.co checkout
$ git init
Step 2: add all code to the repository
$ git add .
Step 3: Save or commit the code in local repository
$ git commit -am 'message or info or write anything'
Step 4: We have added to local repository. We may push that to third-party website like github to keep it secured. To do that we need ssh key.
Step 4a: create a .ssh directory (I created it in F:/myrails using Git Bash)
$ mkdir /f/myrails/.ssh
If you want to create directory in root directory instead of F:/myrails run the following command:
$ mkdir ~/.ssh
Step 4b: generate ssh key
$ ssh-keygen.exe
Step 4c: get ssh key
$ cat id_rsa.pub
Step 5: Login to github.com
Step 6: Go to "Settings > SSH and GPG Keys" and click "New SSH Key" button
Step 7: Input "Title" and "Key" value. Title is optional.
Step 8: Click "Add SSH Key" button.
Step 9: Go to "Settings > Your repositories" and click "New" button
Step 10: Input Repository Name and click "Create Repository" button
Step 11: Copy 3 lines of code under "...or push an existing repository from the command line"
git remote add origin https://github.com/ghoseapu/railsfriends.git [this was for my repository]
git branch -M main
git push -u origin main
Step 12: Go to project location using Git Bash
$ cd /f/myrails/friends
Step 13: Run those 3 lines in Git Bash
git remote add origin https://github.com/ghoseapu/railsfriends.git [this was for my repository]
git branch -M main
git push -u origin main
All is done! Use the following 3 lines (to push to github) when you change any code in this project only
$ git add .
$ git commit -am 'write message'
$ git push