Understanding the Git Workflow: Working Directory, Staging, Commit and Push.
My First GitHub Project: From a Local Folder to GitHub Using Git and SSH Introduction When I started learning Git, I found it a bit confusing at first. I knew GitHub was used to store code, but I did not fully understand how a project on my computer gets connected to GitHub. In this article, I will explain the steps I followed to create a simple project, connect it to GitHub using SSH, and push…
Git is a tool that assists developers in tracking modifications made to their code. When I began learning Git, I discovered it might seem perplexing initially. GitHub is a platform where Git repositories can be stored online. Git enables me to manage my code, whereas GitHub hosts that code on the internet. Furthermore, GitHub simplifies the process for developers to collaborate on projects.
To commence using Git and GitHub, one must first install Git on their computer. This can be verified by opening a terminal and executing the command: git --version. If Git is correctly installed, it will display the installed version.
Following the installation of Git, a project folder should be created. For instance, I created a folder labeled: my-first-project. Once inside the folder, a simple file named: README.md was created and populated with the text: # My First GitHub Project This is my first project using Git and GitHub.
At this juncture, the project remains on my computer. To initiate Git management, the folder must be designated as a Git project. This is accomplished by running the command: git init. This creates a concealed .git folder within the project. The project's status can be inspected using the command: git status. Git displays which files are being tracked and which are still untracked.
To ensure secure communication between my computer and GitHub, SSH (Secure Shell) must be configured. This involves generating an SSH key using the command: ssh-keygen -t ed25519 -C your-email@example.com. The key pair generated comprises a private key (id_ed25519) and a public key (id_ed25519.pub). The public key (.pub file) should never be shared. The private key must be kept confidential.
The SSH key must be added to my GitHub account. On Linux or macOS, this is achieved by executing: cat ~/.ssh/id_ed25519.pub. On Windows PowerShell, the command is: Get-Content ~/.ssh/id_ed25519.pub. This displays the public key, which is then copied. The copied key is subsequently added to GitHub by navigating to: Settings → SSH and GPG keys → New SSH key. The key is given a name, the public key is pasted, and the entry is saved.
Before pushing my project, it is advisable to verify the SSH connection by executing: ssh -T git@github.com. Upon successful authentication, GitHub confirms that the connection is secure.
Subsequently, a repository must be created on GitHub. For example, I named my repository: my-first-project. This repository must not include a README file as I have already established one in my local project. GitHub provides a repository address, which is used to connect my local project to GitHub.
To establish the connection, I navigate to my terminal while inside the project folder and execute: git remote add origin git@github.com:username/my-first-project.git. Here, "origin" is the name Git assigns to the remote repository. The connection is confirmed by running: git remote -v.
The core of the Git workflow involves making changes to my project, staging the modifications, committing the changes, and finally pushing the project to GitHub. Staging involves adding files to the staging area using the command: git add . or git add README.md for specific files. Committing changes is executed with the command: git commit -m Initial commit. The commit message should encapsulate the modifications made. For example: git commit -m Add README.
Finally, the project is pushed to GitHub using the command: git push -u origin main. This transmits the committed files to the GitHub repository, where they become visible. The fundamental Git workflow, after initial setup, simplifies to: Make changes ↓ git add ↓ git commit ↓ git push. GitHub ultimately hosts the project, enabling collaborative development and version control.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.