A brief introduction to Unix, Git, and Github.
What is Unix?
Unix is an operating system. It supports multitasking and multi-user functionality. Unix is most widely used in all forms of computing systems such as desktops, laptops, and servers.
Here are some common basic shell commands which will be useful for some basic operations:
- PWD - Prints present working directory.
`eg: pwd`
- LS - Lists all files and folders in a directory.
`eg: ls`
- CD - Takes an argument about the folder that you want to navigate to.
`eg: cd Documents`
- CD .. - Navigates to one level up.
`eg: cd ..`
- Clear - Clears the screen.
`eg: clear`
- Exit - Exit the terminal.
`eg: exit`
- Man - This is to get the manual of a particular command and It will give all information regarding the cd command.
`eg: man cd`
CRUD-Create, read, update, delete.
- Touch - To create a new text file.
`eg: touch hello_world.txt
- Echo - To type or insert the content in the file.
`eg: echo "Hello" >> hello_world.txt`
- Nano - To edit the content.
`eg: nano hello.txt`
CRUD on Directories:
To create a directory: mkrdir
To move the directory from one location to another: mv
To remove the directory: rm
To copy the files and folders: cp
Git is a version control system that lets you manage and keep track of your source code history.
There are three various stages in git.
- Working tree
(Untracked area)
: This is used to create, update and delete the file. It doesn't start the tracking yet. - Index
(Staging area)
: This is the preparation area and git starts tracking changes in files. And here we can still make changes in files. - History
(Committed stage)
: It keeps the commit-graph. It will create a commit.
There are some commands:
git status
- Check the status of a repository.
git log
- Check the commit history.
git add <file name>
- Add file to staging area.
git commit -m "<message>"
- Moves file from staging area to committed area.
git restore --staged <file name>
- Moves file from staging back to working area.
git checkout <commit Hash>
- Go back to the stage of working tree in a particular commit.
Branching and Merging
Branching is a feature available in most modern version control systems. Instead of copying files from directory to directory, Git stores a branch as a reference to a commit. In this sense, a branch represents the tip of a series of commits. Branching facilitates the development of bug fixes.
Merging Branches. Once you've completed work on your branch, it is time to merge it into the main branch. Merging takes your branch changes and implements them into the main branch. Depending on the commit history, Git performs merges two ways: fast-forward and three-way merge.
We have some commands:
git branch <branchName>
- Creates a new branch.
git checkout <branchName>
- Switches to the specific branch.
git merge <branchName>
- Merges the given branch into current branch.
git branch -d <branchName>
- Deletes the given branch.
git branch -b <branchName>
- Creates and switches to the new branch.
Collaborating via GitHub
GitHub is a cloud-based hosting service that lets you manage Git repositories and helps people solve problems by building software together. GitHub is moisture data sharing. If you have open-source projects that use Git, then GitHub is designed to help you better manage them. GitHub allows multiple people to work on the same project/issue and everyone can get a copy of the project file without disturbing the original copy. So that everyone can add their own data and collaborate all at the end by pull request.
Collaborators on a personal repository can pull (read) the contents of the repository and push (write) changes to the repository. In a private repository, repository owners can only grant write access to collaborators. Collaborators can't have read-only access to repositories owned by a user account.
git clone <remote URL>
- Clones makes a new copy of a remote repo to our local machine.
git fetch origin
- Downloads all changes from origin remote repo to local.
git push origin <branchName>
- Uploads all changes from the local branch to the remote branch.
git pull origin <branchName>
- Downloads all changes from the remote branch to the local branch.
Thanks for reading! Also, if you liked this article, be sure to ❤ it.