{"id":659,"date":"2023-04-22T18:46:54","date_gmt":"2023-04-22T18:46:54","guid":{"rendered":"https:\/\/zinisoft.net\/?p=659"},"modified":"2024-05-29T09:12:29","modified_gmt":"2024-05-29T09:12:29","slug":"how-to-use-git-and-github-for-version-control","status":"publish","type":"post","link":"https:\/\/zinisoft.net\/vi\/how-to-use-git-and-github-for-version-control\/","title":{"rendered":"How to Use Git and GitHub for Version Control"},"content":{"rendered":"

What Is Git?<\/h1><\/h4><\/div>

Git is a free open source distributed version control system you can use to track changes in your files. You can work on all types of projects in Git, from small to large.<\/p>\n

With Git, you can add changes to your code and then commit them (or save them) when you\u2019re ready. This means you can also go back to changes you made before.<\/p>\n

Git works hand in hand with GitHub \u2013 so what is GitHub?<\/p>\n<\/div><\/div><\/div>

\"Git<\/span>
Git & GitHub<\/div><\/div><\/div><\/div>

What Is GitHub?<\/h1><\/h4><\/div>

GitHub is a web interface where you store your Git repositories and track and manage your changes effectively. It gives access to the code to various developers working on the same project. You can make your own changes to a project at the same time as other developers are making theirs.<\/p>\n

If you accidentally mess up some code in your project while making changes, you can easily go back to the previous stage where the mess has not occurred yet.<\/p>\n<\/div><\/div><\/div>

Why Use GitHub<\/h1><\/h4><\/div>

There are so many reasons you should learn and use GitHub. Let\u2019s look at a few of them now.<\/p>\n<\/div>

Effective Project Management<\/b><\/p>\n

GitHub is a place where your Git repositories are stored. GitHub makes it easy for developers working on the same project but in different locations to be on the same page.<\/p>\n

With GitHub, you can easily track and manage the changes you have made and check on the progress you\u2019ve made in your project.<\/p>\n

Easy Collaboration And Cooperation<\/b><\/p>\n

With GitHub, developers from all over the world can work together on a project without having any problems.<\/p>\n

Teams are able to stay on the same page while working on a project together and can easily organize and manage the project effectively.<\/p>\n

Open Source<\/b><\/p>\n

GitHub is a free and open source system. This means that developers can easily access different types of code\/projects which they can use in learning and developing their skills.<\/p>\n

Versatility<\/b><\/p>\n

This attribute of GitHub is very important. GitHub is not a web interface for only developers. It can be used by designers, writers, and anyone who wants to keep track of the history of their projects.<\/p>\n<\/div><\/div><\/div>

How to Setup Git<\/h2><\/h4><\/div>

To start using Git, you’ll need to download it to your computer if you haven’t already. You can do this by going to their official website.<\/p>\n

When Git opens, scroll down a bit and you should see a download button. Go ahead and click on it.<\/p>\n<\/div>

\"Download<\/span>
Download button on the Git website<\/div><\/div><\/div><\/div>

Choose your operating system whether it’s Windows, MacOS, Linux\/Unix. In my case, I will be choosing the Windows option because I am using a Windows computer:<\/p>\n<\/div>

\"Choose<\/span>
Choose your operating see you system<\/div><\/div><\/div><\/div>

Click on the first link at the very top of the page to download the latest version of Git.<\/p>\n<\/div>

\"Download<\/span>
Download the latest version of Git by clicking the first link<\/div><\/div><\/div><\/div>

When the download is complete, then go ahead and install Git to your computer. You’ll need to go to the location where the file has been downloaded and install it.<\/p>\n

After the installation, you’ll want to make sure that Git is successfully installed on your system. Open your command prompt or Git bash (whichever one you choose to use) and run the command:<\/p>\n

\n

git –version<\/p>\n<\/blockquote>\n

If Git was successfully installed on your computer, it should display the current version of Git below the command you just ran. If the current version is being displayed, congratulations!<\/p>\n<\/div><\/div><\/div>

How to Configure Git<\/h2><\/h4><\/div>

Now that we have installed Git on our computer, we have to configure it. We do this so that any time we are working in a team on a project, we can easily identify the commits we have made in the repository.<\/p>\n

To configure Git, we need to specify the name, email address, and branch by using the git config --global command.<\/i><\/code><\/span>\n<\/p>\n

\n

git config –global user.name \u201c [username]\u201d<\/p>\n

git config –global user.email<\/p>\n

git config –global init.default branch main<\/p>\n<\/blockquote>\n

For example:<\/p>\n

\n

git config –global user.name \u201cZini\u201d<\/p>\n

git config –global user.name zinisoft@gmail.com<\/p>\n

git config –global init.default branch main<\/p>\n<\/blockquote>\n

We used git config --global user.name<\/i><\/code><\/span> to configure the username. In my case I used my name \u201cZini\u201d<\/i><\/code><\/span>. The same applies for the git config --global user.email<\/i><\/code><\/span><\/p>\n

Git comes with a default branch of master, so I changed it to be called the main branch by using the git config --global init.default branch main command<\/i><\/code><\/span>.<\/p>\n

Now you’re ready to start using Git.<\/p>\n<\/div><\/div><\/div>

How to Setup Git Account<\/h2><\/h4><\/div>

To start using Git, you’ll need to download it to your computer if you haven’t already. You can do this by going to their official website.<\/p>\n

When Git opens, scroll down a bit and you should see a download button. Go ahead and click on it.<\/p>\n<\/div>

<\/span><\/div>

When the sign up form opens up, enter your email, create a password, enter your username, and then verify your account before clicking on the create account button.<\/p>\n<\/div><\/div><\/div>

Commonly Used Git Commands<\/h2><\/h4><\/div>

There are some basic Git commands that every developer should know how to use:<\/p>\n

\n

git config
\ngit init
\ngit add
\ngit commit
\ngit clone
\ngit push
\ngit rm\n<\/p>\n<\/blockquote>\n

Let’s go through each of these briefly so you know how to use them.<\/p>\n<\/div><\/div><\/div>

How to Use the\u00a0 git config<\/span><\/span>\u00a0Command<\/h3><\/h4><\/div>

You use this command to set the username, email, and branch of a user so as to identify who made a commit when working on a project. This command is used when you have downloaded git into your computer and you want to customize it for your use.<\/p>\n

For example:<\/p>\n

\n

\ngit config –global user.name \u201c [username]\u201d
\ngit config –global user.email [email address]\n<\/p>\n<\/blockquote>\n

git config --global user.name<\/i><\/code><\/span> to configure the username. In my case I used my name \u201cZini\u201d<\/i><\/code><\/span>. The same applies for the git config --global user.email.<\/i><\/code><\/span><\/p>\n

Git comes with a default branch of master, so I changed it to be called the main branch by using the git config --global init.default branch main command.<\/i><\/code><\/span>\n<\/p>\n

Now you’re ready to start using Git.<\/p>\n<\/div><\/div><\/div>

How to Use the\u00a0 git init<\/span><\/span>\u00a0Command<\/h3><\/h4><\/div>

You use the git init<\/i><\/code><\/span> command to start Git in your project. This git command is used when you are working on a project and would like to initialize git to the project in order to keep track of the changes made in the project.<\/p>\n

For example:<\/p>\n

\n

git init<\/p>\n<\/blockquote>\n

When you run this command, you should see a folder named .git<\/i><\/code><\/span> being created automatically in the current folder you are working on.<\/p>\n<\/div><\/div><\/div>

How to Use the\u00a0 git add<\/span><\/span>\u00a0Command<\/h3><\/h4><\/div>

This command adds your file to the staging area. The staging area is the area where files we make changes to are added and where they wait for the next commit.<\/p>\n

To add a file to the staging area, you use the git add<\/i><\/code><\/span> command. It adds all the files in the folder to the staging area.<\/p>\n

git add (file name)<\/i><\/code><\/span> adds the name of the particular file you want to commit in the staging area.<\/p>\n

Use this command when you have made changes to a file and want to commit them to your project.<\/p>\n<\/div><\/div><\/div>

How to Use the\u00a0 git commit<\/span><\/span>\u00a0Command<\/h3><\/h4><\/div>

This commits any file you added with the git add<\/i><\/code><\/span> command as well as every file in the staging area.<\/p>\n

For example:<\/p>\n

\n

git commit \u2013m \u201cfirst commit\u201d<\/p>\n<\/blockquote>\n

This command saves a file permanently to the Git repository. You use it whenever a file has been added to the staging area using the git add<\/i><\/code><\/span> command.<\/p>\n<\/div><\/div><\/div>

How to Use the\u00a0 git clone<\/span><\/span>\u00a0Command<\/h3><\/h4><\/div>

You use the git clone<\/i><\/code><\/span> command to copy an existing repository in another location to the current location where you want it to be.<\/p>\n

\n

git clone (repository name)<\/p>\n<\/blockquote>\n

You use this command when you want to duplicate a Git repository from GitHub into your local storage.<\/p>\n<\/div><\/div><\/div>

How to Use the\u00a0 git push<\/span><\/span>\u00a0Command<\/h3><\/h4><\/div>

You use this command to upload\/push files from the local repository\/storage to another storage, like a remote storage such as GitHub.<\/p>\n

For example:<\/p>\n

\n

git push (remote storage name)<\/p>\n<\/blockquote>\n

You only use this command when you’re satisfied with the changes and commits you’ve made on a project and finally want to upload\/push it to the Git repository in GitHub.<\/p>\n<\/div><\/div><\/div>

How to Use the\u00a0 git rm<\/span><\/span>\u00a0Command<\/h3><\/h4><\/div>

You use this Git command to remove a file from a working repository. For example:<\/p>\n

\n

git rm (filename)<\/p>\n<\/blockquote>\n

You use this command only when you wish to get rid of an unwanted changes\/files from the Git repository.<\/p>\n<\/div><\/div><\/div>

How to Use the\u00a0 git branch<\/span><\/span>\u00a0Command<\/h3><\/h4><\/div>

You use this command to check the current branch you are working on, either main<\/i><\/code><\/span> or master<\/i><\/code><\/span>. For example:<\/p>\n

\n

git branch<\/p>\n<\/blockquote>\n

This command helps you know the current branch you are working on.<\/p>\n<\/div><\/div><\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"

A Version Control System is a tool you use to track, make, and manage changes to your software code. It’s also called source control.<\/p>\n","protected":false},"author":1,"featured_media":660,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[32],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/posts\/659"}],"collection":[{"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/comments?post=659"}],"version-history":[{"count":11,"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/posts\/659\/revisions"}],"predecessor-version":[{"id":4517,"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/posts\/659\/revisions\/4517"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/media\/660"}],"wp:attachment":[{"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/media?parent=659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/categories?post=659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zinisoft.net\/vi\/wp-json\/wp\/v2\/tags?post=659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}