This content originally appeared on DEV Community and was authored by aashiya123
Git is a free and open-source distributed version control system that handles every change within the project. Git software runs on the local machine to keep track of the files and their history. You can also use Git’s online hosts to store files. It also allows you to have a centralized place to store files to ensure easy access. With Git, you can easily make parallel changes that can be merged later without any issue.
Features of Git
- It allows you to track history.
- It is a free and open-source distributed version control system.
- It supports non-linear development.
- It allows you to create backups.
- You can scale it according to your business needs.
- It enhances team collaboration.
- It ensures easy branching.
- It supports distributed development.
*Git workflow *
- Git workflow has three different stages-
- Working directory- it allows you to alter the files and codes within your working directory.
- Staging area- it allows you to stage the files and add their snapshots to the staging area.
- Git directory or repository- it allows you to commit the modification permanently.
Basic Git commands
Creating a repository
Creating a new local repository from scratch
$ git init [project name]Downloading from an existing repository
$ git clone my_url
Observing your repository
Listing new or modified files that are not being committed yet.
$ git statusDisplaying the file changes that are not being staged
$ git diffDisplay the change to the staged files
$ git diff --cachedDisplay all the staged and unstaged file changes
$ git diff HEADDisplay the differences between two commit ids
$ git diff commit1 commit2Listing the dates and the author of the changed file
$ git blame [file]Display the file changes for a particular id or a file
$ git show [commit]:[file]Display the complete change history
$ git logIt will display the change history for a particular file or a directory
$ git log -p [file/directory]
Working with branches
It will display all the local branches
$ git branchIt will display all the local as well as the remote branches
$ git branch -avIt will switch to a branch and will update the working directory accordingly
$ git checkout my_branchIt will create a new branch named new_branch
$ git branch new_branchIt will delete the branch named my_branch
$ git branch -d my_branchIt will merge two branches, branch_a, and branch_b
$ git checkout branch_b
$ git merge branch_aIt will tag the current commit.
$ git tag my_tag
Making changes
To stage the file and ready to commit
$ git add [file]It will stage all the changed file and ready to commit
$ git add .It will commit all the staged files to the versioned history
$ git commit -m “commit message”It will commit all the tracked file to the versioned history
$ git commit -am “commit message”It will unstage the file and keep the file changes
$ git reset [file]It will revert everything to the last commit
$ git reset --hard
Synchronize
It will get the latest changes from the origin
$ git fetchIt will fetch the latest changes from the origin and merge
$ git pullIt will fetch the latest changes from the origin and rebase
$ git pull --rebaseIt will push the local changes to the origin
$ git push
Help command
- Use the git help command for more details $ git command --help
This content originally appeared on DEV Community and was authored by aashiya123
aashiya123 | Sciencx (2021-12-28T05:41:38+00:00) Git Commands Cheatsheet: Beginners (18-20+ basic Git Commands). Retrieved from https://www.scien.cx/2021/12/28/git-commands-cheatsheet-beginners-18-20-basic-git-commands/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.