Sharing A Gifting, Git !

git add, git commit, git push

Dong Xia
5 min readSep 11, 2020

As a new developer, we will come across this “Git” word so many time. What is git? Why is it so important?

Git

All it means, its a version control system. There are many copies of the code at different points in time. It can be thought as save points. We have the ability to go back in time to a specific save point using special git commands. We’ll be using the most popular git, GitHub in our examples.

Vocabulary

Like all languages, we need to learn the basic words to form complete sentences. At first it might feel difficult but it gets easier once you understand the basics. Here are some basic words and their english translation.

repo — a folder.

init — initialize a communication between your local repo and the remote(GitHub) repo.

fork — copy someone else’s repo onto your GitHub account.

clone — copy someone else’s repo onto your local desktop.

main — the main path, the trunk of the tree.

branch — a new path that diverge from the main path at a certain point in time.

merge — Combining your branch back into the master branch.

checkout — switching, going onto another branch.

add — adding all files that you want to be save.

commit — save

push — upload your file/version onto GitHub.

pull — download the latest file/version onto your desktop.

local — your desktop computer.

remote — your GitHub account.

Getting Started

Step 1. Create an account on GitHub.

Step 2. On the terminal run

brew install git 

Step 3. Connecting your computer to GitHub. When asked for your password, enter your password, it will be invisible.

git config — global user.email “you@example.com”git config — global user.name “Your Username”

Step 4. Find and copy the SSH Key, the terminal should prints out a long string of characters starting with ssh-rsa

cat ~/.ssh/id_rsa.pub

Step 5. If nothing get printed onto the terminal, run

ssh-keygen

Step 6. Repeat step 4.

Step 7. On GitHub, under settings > SSH and GPG keys. Click on the New SSH Key in the upper right corner.

Step 8. Paste the SSH key and click on the add SSH key button.

Step 9. Verify by entering your password.

Step 10. Your all set ready to use GitHub.

Creating your first Repo

Step 1. Under the repository tab, click on the new button.

Step 2. In the Repository name. create a name for your folder(project).

Step 3. On your local computer, create a new folder with the exact same name as the repository name. (e.g. new_example)

Step 4. cd into your new folder and run these commands

git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:YourUserName/YourFolderName.git
git push -u origin main

Step 5. Congratulations. You created your first repo.

Working with a partner on a project

GitHub is a platform where we share our works. We can work on them locally, remotely, or with other developers. It can be challenging because of merge conflicts. Here are some commands that are really helpful in getting started.

git add .                          -adding the work to upload
git commit -m "some log" -saving the work
git push -uploading the work
git push -u origin -uploading the master (1st time)
git push -u origin branch_name -uploading the branch(1st time)
git branch -see local branches
git branch -a -see all branches
git remote -v -see link GitHub account
git checkout -switch branch
git checkout -b -create & switch to new branch
git checkout -t origin/branch_name -create & switch to remote branch
git branch -d branch_name -delete local branch
git push origin -d branch_name -delete remote branch
git branch -d -r origin/branch_name -delete remote tracking branch
git pull -get the latest update and merge
git log -see past commits
git reset -unstage the files
git reset --hard <commit number> -reset to a past commit
git reset --soft <commit number> -reset to past commit changes are
still staged.
"the soft reset won’t alter the working directory and the index."
"to combine many different commits into a single one"
git push -f origin -force push & alter repo
"Your branch is behind 'origin/master' by n commit"
"When you git reset --hard or --soft"

Contribute to another person repository

  1. Find someone else repository that you would like to contribute.
  2. Fork over their repository into your Github account.
  3. Then clone their repository onto your local computer.
  4. cd into the project folder that was cloned down onto your local computer.
  5. git remote rename origin “new name”. The standard Git naming conventions will be → git remote rename origin upstream. upstream representing the original repository SSH/URL(read only).
  6. git remote add origin “your SSH/URL”. This will be your forked version from your Github(read and write).
  7. Now when you do git remote -v you will see two remote branch, origin and upstream.

8. After making changes to your forked version. git push

9. On your Github account, select pull request

10. the base repository original version ← head repository your forked version

Go Explore The World of Git !!!!!

Photo by Jamie Street on Unsplash

--

--