Understanding the Git Workflow:Working directory,staging ,commit and push.
What is Git and Github This is a version control system or tool used to track changes by developers. When one installs git it comes with an inbuilt terminal called gitbash Github is a cloud based platform for storing git repositories online. Just sign up for free,verify via email and your account is created. git and github are connected using a SSH KEY. How Git works. We start by installing git…
Git is a version control system that tracks changes made by developers. Upon installation, Git includes a built-in terminal called GitBash. Github is an online platform to store Git repositories, which can be accessed after signing up for free and verifying via email. The connection between Git and Github is established using an SSH key.
To begin using Git, first install it on a personal computer and verify its installation by running `git --version` in a terminal. Git's workflow consists of four stages: the working directory, staging area, local repository, and remote repository. Within the working directory, developers write, modify, and delete files. The changes made are not tracked until instructed to commit.
The staging phase prepares files for committing by modifying them, after which the commit phase takes all changes from the staging area and saves them to the local repository. The push phase finally transmits the saved commits to a remote repository like Github.
Creating folders and files on GitBash starts by identifying the desired location using `ls` to list directories, `mkdir` to create a new one, and `cd` to navigate into it. README files are written using Markdown language, typically ending with `.md`. To create or initialize a repository, use `git init`, followed by `git status` to check the repository status and see any changes.
The `git add` command stages the changes made, with `.git add .` staging all files or specifying a file name like `git add script.js`. Committing records the staged changes in the local Git repository with a snapshot or memory of the file, using `git commit -m "commit message"`. To view the history of commits, run `git log`.
To push commits to a remote repository like Github, first create an account and a new repository, then copy the SSH link. In GitBash, add the remote repository using `git remote add origin` followed by the SSH key link. Test the connection using `git remote -v`, then push the commits with `git push -u origin main`. This sends the files to the Github repository, and refreshing the page will display the changes.
A SSH key, or Secure Shell key, is a protocol that enables secure communication between computers over a network. To generate an SSH key, run `ssh-keygen -t ed25519 -C email signed on github.com`, and optionally provide a passphrase. This command generates two keys, a public key that should be shared with Github, and a private key that should remain confidential. Add the public key to Github's SSH and GPG keys settings, then test the SSH connection using `ssh -T git@github.com`.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
This story
This is one outlet's version. Read the fullest account.