DEV Community

Ravindra singh
Ravindra singh

Posted on

GIT for Beginners

Hello Readers! welcome to this Git series of tutorials.

i'll divide this series into different topics, so please hang in there.

For the starting i'll start with basics!


What is a GIT?

Git is a version Control Software which is used to maintain change history of a codebase.


What is a GitHub?

GitHub is a online website which is used to store all these git commit histories.


How to install Git?

To install git on linux host we can use these following commands.
Note: Please refer to the official website if case of any errors!!

sudo apt update
sudo apt install git-all
Enter fullscreen mode Exit fullscreen mode

How to confirm successful installation of the Git?

to ensure git is available on the local machine, we can check it's version by using the command!

git --version
Enter fullscreen mode Exit fullscreen mode

How to initialize a Git repository on the local machine!!?

to instalize a git repository on the local machine.

  • Step 1 : navigate to the given directory
  • Step 2 : initialize the git repository
git init
Enter fullscreen mode Exit fullscreen mode

How to ignore certain files in git?

sometimes there are certain files which we dont want to upload on remote repository. to make this happen, we need to add the name of that file into .gitignore file

echo <filename> >> .gitignore
git add .gitignore
git commit -m "Git ignore file added"
Enter fullscreen mode Exit fullscreen mode

How to manage Git branches

How to create a new branch?

branches contains sequence of commits in git.
we can create or delete as much as branch as we required.

To create new branch

# this command will create a new branch with given branch name
git branch <branch-name>
# this command will create a new branch and switch to that branch
git checkout -b <branch-name>
Enter fullscreen mode Exit fullscreen mode

How to rename a branch

to rename a branch in git, use the given command!

# first switch to the main branch
git checkout <branch-name>

# second use the following command to change the branch name
git branch -m <old-name> <new-name>
Enter fullscreen mode Exit fullscreen mode

How to delete a branch

to delete a branch in git we use.

git branch -d <branch-name>
Enter fullscreen mode Exit fullscreen mode

How to watch the commit history

to watch the commit history we have git log command

git log
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
bobbyiliev profile image
Bobby Iliev

Well done! πŸ‘

For anyone interested in learning more, you can checkout this free ebook here:

GitHub logo bobbyiliev / introduction-to-git-and-github-ebook

Free Introduction to Git and GitHub eBook

πŸ’‘ Introduction to Git and GitHub

This is an open-source introduction to Git and GitHub guide that will help you learn the basics of version control and start using Git for your SysOps, DevOps, and Dev projects. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you can use Git to track your code changes and collaborate with other members of your team or open source maintainers.

The guide is suitable for anyone working as a developer, system administrator, or a DevOps engineer and wants to learn the basics of Git, GitHub and version control in general.

πŸš€ Download

To download a copy of the eBook use one of the following links:

πŸ“˜ Chapters

Collapse
 
diwancdac profile image
diwancdac

Great... thanks for sharing