Introduction
In this article I will explain my practical experience of creating Git repository,connecting it to GitHub using SSH,commiting my files and pushing the project to a remote repository.
Step 1 :Creating My Local Project
The first step is to create a folder through file explorer which as the best option for me and name it (my-project)
Next step was to open GitBash and run the command
cd my- project
To open the file directory
Step 2 : Initializing Git
This is to tell Git that my my-project folder should become a Git repository.
To initialize Git I ran the command:
git init
Step 3:Repository Status Check
After initializing Git, I used :
git status
This command is very useful as it can be used throughout the process it tells what's happening inside my repository.
At some point people may encounter:
On branch main
Nothing to commit, working on a tree clean
It could seem like an error,however I learned that this means Git has checked my project and found no changes that need to be committed.
Another situation that I encountered is where Git told me that the older my project was already initialized .This taught me to use the command:
git status
To understand the current status of my project.
Step 4:Connecting GitHub Using SSH
The next thing I learnt was on how to generate SSH key which will be used to connect my computer securely to GitHub.
To generate an SSH key I ran the command:
ssh-keygen -t ed25519 -C "your_email@example.com"
Under the double quotes use the email used for your GitHub account.
Then press entre to save it on the default location.
You'll then be told to enter passphrase which is simply a password,create a simple one which you can memorize easily like 1234.Then entre it again when asked.
You then start the SSH agent
Run;
eval "$(ssh-agent -s)"
Then add your SSH keyy
Run:
ssh-add ~/ .ssh/id_ed2559
It will ask you to entre the passphrase you created.
Copy your public key y running the command:
cat ~ .ssh/id_ed25519 .pub
Add the entire line generated by coping it then go on GitHub-Settings-SSH and GPG keys-New SSH key,give it a title and paste the public key and save it.
Then test the connection ack in Git Bash through the command:
ssh -T git@ithub.com
Step 5:Creating a Repository on GitHub
Log in to your GitHub account on the far right click on your profile scroll down to repositories press the option.
After that create your repository,give it a title, add a small description about it ,choose its visibility to public finally press create repository.
Step 5:Adding Files
This means to prepare the files and add changes in the current directory.
To do this one runs the command:
git add .
I could then check the status again:
git status
The files would appear as changes ready to be committed.
Step 6:Create a Commit
This stage is like a saved checkpoint in my project.
To create a Commit run the command:
git commit -m "Initial commit"
The message "Initial commit" is just a commit statement which can be different to your preference.
Step 7:Connect the Local Repository to GitHub
I connected my local repository to GitHub
Firstly one should open GitHub go to where he repository you created is click on it then copy the SSH which is used as a location key.
Then using the command :
git remote add origin (paste the SSH key copied from GitHub)
Then to check whether the connection was established we use the command :
git remote -v
Then to ensure your current branch is called main use the command:
git branch -M main
Step 8:Push the Project to GitHub
To push the folder
I used:
git push -u origin main
The -u option sets the remote ranch as the upstream branch .This means that later I can usually use:
git push
Then go to your GitHub and click on your repository, you will find the folder my-project inside your online GitHub repository.
Conclusion
Creating my first GitHub project helped me move from simply having files on my computer to managing a project using a professional development workflow.
To understand the Git command projects I came up with my own mnemonic "I See All Commits Reach Big Places"
git init
git status
git add .
git commit"commit statement"
git remote add origin <repository-url>
git branch -M main
git push -u origin main
Top comments (0)