DEV Community

Cover image for Git Intro for Beginners
Kwerenachi Utosu
Kwerenachi Utosu

Posted on

Git Intro for Beginners

What is Git?
Git is a free, open source distributed version control system tool designed to handle everything from small to very large projects with speed and efficiency. Git has the functionality, performance, security and flexibility that most teams, individual developers and researchers need. It was created by Linus Torvalds in 2005 to develop Linux Kernel.

What is the purpose of Git?
Git is primarily used to manage your project, comprising a set of code or text files that may change that may change over time.

Git is also used to save your remotely and allow access to multiple individuals for updates.

Here are 15 git commands to master for a start

git init
This command is used to initialize or start a new git repo
see sample below. Navigate into the folder you're initializing if it already exist, or simply create a new one.

Alt git init

git config
The git config command sets the author name and email address respectively to be used with your commits.

Alt git config

git clone
This command is used to obtain or download a repository
from an existing source.

Alt git clone

git add
This command is used to add a single file or multiple files to a staging area. Note that, the added file(s) won't be on your remote environment until they're pushed.

Here are some git add commands

  • git add filename adds a file called "filename" to the staging area
  • git add . stages new files and modifications, without deletions
  • git add -A stages all changes
  • git add -u stages modifications and deletions, without new files

Alt git add

git commit
This command records or snapshots the file permanently in the version history.

Here are some git commit commands

  • git commit -m "My First Commit" gives you the opportunity to add a commit message.
  • git commit -a commits any files you’ve added with the git add command and also commits any files you’ve changed since then.

Alt git commit

git remote
This command is used to connect your local repository to the remote server.

Alt git remote

git status
This command lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. Status output does not show you any information regarding the committed project history.

Alt git status

git fetch
The command is a primary command used to download contents from a remote repository. This content includes branches and tags.

Alt gitfetch

git checkout
This command is used to switch from one branch to another.

Alt git checlout

This command can be used to create a new branch. To create a new git checkout -b my-new-branch where "my-new-branch" is the name of the new branch.

Alt git checkout2

git push
This command sends information committed to your remote repository. when using git push you can there are multiple way commits can be pushed to the remote.

  • git push [remote-variable-name] [branch-name] this command pushes commits staged on a particular branch to a remote origin, example git push origin master we can also have git push heroku my-new-branch.
  • git push all this command pushes all branches to your remote repository.
  • git push -force or git push -f this command forcefully send the current staged commit to the remote repository.
  • git push -u origin master is used for pushing staged content to GitHub. In the code, the origin is your default remote repository name and -u flag is upstream, which is equivalent to -set-upstream and the master is the branch name.

Alt gitpush

git pull
This command fetches and merges changes on the remote server to your working directory.

Alt gitpull

git stash
This command temporarily stores all the modified tracked files. this command can also be used to check all new modifications and move them to a new branch.

Alt git stash

  • git stash pop this command restores the most recently stashed files on the current branch.
  • git stash list this command lists all stashed changes.
  • git stash drop this command discards the most recently stashed changes.

git merge
This command merges the specified branch’s history into the current branch.

git branch
This command lists all the local branches in the current repository. This command can also be used to create a new branch or delete an existing branch.

  • git branch new-branch-name this command creates a new branch called "new-branch-name".
  • git branch -d [branch-name] this command deletes the feature branch.

Alt git branch

git log
This command is used to list the version history for the current branch.

Alt git log

You can start by practicing these few git commands, using them constantly also helps to learn them faster. I hope you have a great learning experience.

To get a more in-depth knowledge of git please click here learn git

Top comments (2)

Collapse
 
anirudhann profile image
Anirudhan

Thanks for the quick refresh in git basics !!

Collapse
 
kwereutosu profile image
Kwerenachi Utosu

You’re welcome 💪🏼