DEV Community

loading...
Cover image for Quick review on git commands

Quick review on git commands

claranceliberi profile image Clarance Liberi 💯 Updated on ・2 min read

In this blog we are going to review some basic git commands, we are going to work through all essential git commands that you need to start working with git efficiently and productive

Setting up git

After downloading and installing git bash you will need to set up this information so that git can start working properly but this will only be set once , unless you re-install new git

# - check git version
git --version

# - configure you Name and your email to identify yourself with Git
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
Enter fullscreen mode Exit fullscreen mode

Initializing/creating repository

in case you are creating new repository to track your file changes
you will need to use this command

# - initializing git repository
git init
Enter fullscreen mode Exit fullscreen mode

Status [ of the repository]

when you want to see the status of the files in the repository, again in the current branch you will use this command which will show untracked files etc

# - show status of the repository
# - shows files which have been changed,
#   tracked, staged etc
git status
Enter fullscreen mode Exit fullscreen mode

Stagging files

all about adding files to git repository, notice that you can use remove instead of add if you want to unstage files or remove files

# - staging :   adding files to stage area
# - staging area :  files that are going to be included 
#               in next commit


# - staging one file
git add file.js

# - staging multiple files
git add file.js file2.js file3.js

# - staging all files
git add .

Enter fullscreen mode Exit fullscreen mode

Committing file [or stagging files]

saving changes you made in the repository.

# - commit : a term used for saving changes
#           to a repository

# - committing changes made from stagged files
# - '-m' means message , a message should be descriptive
# - showing what changes really made in the repository
git commit -m "Commit message"
Enter fullscreen mode Exit fullscreen mode

History [of the repository]

list of necessary commands that you need to work through your git repository history.

# - view your commit history
git log

# - revert / go back to certain commit
# - '07e239f2f' is a sample commit id that we are
#   trying to go back on 
git checkout 07e239f2f

# - going back to the latest commit on 
#   the 'master' branch
git checkout master
Enter fullscreen mode Exit fullscreen mode

Branches

list of commands that you will work with to interact with branches in the repository

# - Creating new branch
# - 'new-branch-name' is the name of the new branch
git branch new-branch-name

# - switching to branch in the repository
# - if branch 'branch-name' does not exists 
#   on the repository git will create it
git switch  branch-name

# - switch to any branch in the repository
# - 'master' is the branch we want to switch on
git checkout master


# - list all branch in the repository
git branch

#merge 'branch-name' to active branch   
git merge branch-name

# - delete branch
# - 'branch-name' is the branch we are deleting
git branch -d branch-name

Enter fullscreen mode Exit fullscreen mode

Conclusion
All of these commands are super easy to work with as they are easily explained , with them you can start using github or any other tool so that you can now control versions of your system , and I am pretty sure that it is a good note for those who already know git, Thank you

Discussion (2)

pic
Editor guide
Collapse
damosse31 profile image
Tapa10Bal? • Edited

I think git merge description is wrong 🤔

It should be reversed :

# merge branch branch-name to active branch
git merge branch-name
Enter fullscreen mode Exit fullscreen mode
Collapse
claranceliberi profile image
Clarance Liberi 💯 Author

absolutely, thanks . fixed