How to use GIT in shell (basics)
Tags: git, beginners
Published: 2022-10-07 04:25:19

On my full-stack developer journey I've found, that making notes during your learning is a great way to remember stuff. You can also go back to your notes, if you need some help.

**If you are new to GIT, you can should read a git handbook here:** [https://docs.github.com/en/get-started/using-git/about-git]

####[Here you can learn the branching]:
(https://learngitbranching.js.org/)

##I summarized basics here.

When we are in a local bash and in particular project directory, here is what we can do.

####git phases are:

- WORKING DIRECTORY
- STAGING AREA
- LOCAL REPOSITORY
- REMOTE REPOSITORY

####1. To **INITIALIZE** a git
_git init_

####2. To **INCLUDE ALL FILES** (those listed in .gitignore are omited
_git add ._

####Premade templates for .gitignore files
[https://github.com/github/gitignore]

####3. To **CREATE A LOCAL STAGE**
_git commit -m "Initial Commit"_

####4. To **PUSH** commits to a remote repository
Push the git to the origin main (remote)
Don't forget to commit changes first, then  :

_$ git commit -m "Your commit stage description"_
_git remote add origin https://github.com/DeLucasso/NAME_OF_GIT.git_
_git branch -m main_
_git push -u origin main_

####5. To **RESET** to some specifid commit
Use _git log_ command to find a hash of commit that you'd like to reset back to.
_git reset --hard [hash]_

####6. If you want to **PRESERVE** your work, you can use the stash command:
_git stash
git reset --hard [hash]
git stash pop
_

####7. To **IGNORE** (omit) files from the git repository to be uploaded to GitHub: First create a hidden file gitignore
_touch .gitignore_

####8. To **ADD** files to the .gitignore file 
_open .gitignore_

####9. To **REMOVE ALL** files from git stage
_git -rm --cashed -r ._

####10. To **REMOVE SINGLE** file from git stage
_git -rm --cashed filename.txt_

####11. To **GET A STATUS** a status of git
_git status_

####12. To **GET A LOG** of the git stage
_git log_

####13. To put a **COMMENT** into .gitignore use #
_#This is a comment line in .gitignore_

####14. To use **WILDCARDS** in .gitignore
_*.txt_

[An article to understand git branching:]
(https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging)

####15. To **MAKE A NEW** a new branch
_git branch -m new_branch_name_

####16. To **CHECK** branch list
_git branch_

####17. To **SWITCH** a branch ( Check Out ), then you can see '*' at 
_git checkout branch_name_

####19. To **RENAME** a local branch
_git -m old_name new_name_

####20. To **DELETE** a LOCAL branch
First you have to checkout a branch that you want to delete (if its' marked as *)
Then you can delete a branch
_git -d branch_name_to_delete_

####21. To **DELETE** a REMOTE branch
_git push origin --delete branch_name_

####22.!! Everytime when you want to **COMMIT** changes to the git, you have to do this every time:
_git add ._ // (to include all files to git)
_git commit -m "Your commit comment of the changes you've made"_

####21. To **MERGE** a branch to main, don't forget to add all files and commit changes first!
First if you are happy with the changes in branch, you can merge the branch with main

_git checkout main_
_git merge name_of_branch_that_you_want_to_merge_

The vim editor will open, so you can add comments to merge. Then to save it, just write:
 _:q!_

##That's it folks. I wrote everything in an order, that you will probably use it. I hope it help you with a git commands in shell.

[Here is my github repo:](https://github.com/DeLucasso/git/blob/main/how_to_use_git.txt)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uabfruzfx881xc4pm0wp.png)