Simply Perform Version Control by Git - Easy Instruction

Simply Perform Version Control by Git - Easy Instruction

02, Nov, 2018 | Apps | Wei Zhang | 2

Firstly, you need to download Git and install it into your system:

Download Git

Choose your Operating System, and download the newest version.

Today, I used Git 2.19.1 on windows to do this.

1. Run “Git Bash”, if you cannot find it, just search “git” in windows.

After you run it, you will see a git command line windows just like the windows command line.

First thing first, input this command to update the version to the latest one:

git clone https://github.com/git/git

Then here are some basic command line commands you will need for Git:

cd c:/some_folder/ Go to the directory after the command

cd.. Go to parent directory

cd /sub_folder Go to sub-directory

-x When you see a command followed by a “-” plus a letter, it means the arguments for the command which allows the command to perform the behavior in a different way. For example: “git push -f ” means Force to Update remote refs along with associated objects ignore warnings.

The following are some commonly used Git commands:

config

help

init

clone

fetch

pull

push

remote

diff

clean

2. Find the Local Repository directory (Or the directory which stores your projects), for example:

cd C:/Users/WEI/Documents/NetBeansProjects

Note:

*“/” is used for specifying different directories level in the command line, not “\”.

*If your directory or path includes a space, command line will not recognize it as a directory or path, type in “\” before you type space, the system will recommend you the correct one.

After you have reached the target directory, used command “git init” to initial the version control in this folder. You will find you have a new “.git” folder appears in that directory. And the directory now is called “Master”.

3. Now you have initial the git local repository, you now need to confirm and add which projects will be included in the version control.

Type in command “git cmmit -a” then “git add -A” to commit all files and folders in “master” or you can choose the one you want by giving a specific directory and file option.

4. Now, you have the local “master” folder, but you also need an “origin” folder from an online server to store and synchronize all the changes for your projects. Many companies provide the free server for version control, GitHub is free but they will public your codes. I recommend BitBucket repository. They provide free private online repository service. Register it through the following URL: Register Bitbucket

When you have finished the registration, you should be able to create a new repository in your bitbucket dashboard page by a “+” button on the top left of the page. Then name your repository, then it turns to the repository home page. You will see a URL like https://mygitexpample@bitbucket.org/myaccount/web_projects.git which will be followed by a “.git”. This is your online repository path which also called “origin” by git.

Tap in the following command into Git Bash to set up the “origin” to Git:

git remote add origin https://mygitexpample@bitbucket.org/myaccount/web_projects.git

5. Congratulations, you have set up all the basic things for git up and running, now you can use the command to push your files to the server.

git push -u origin master

For more specific operating on Git, please read the document.

Git Documentation

For different settings in various IDEs, I will include those contents in another post.

--

Web Design | Graphic Design | Apps | Software | Blog | Fashion

Like our post?
share it

We will be so proud if you share our post to your social media, also you can leave some comments below.

3 Comments

Lion Commented 98 days ago

I made a mess and fond there are something already in the origin, so the system does not allow me to push my project in.

Cazz Commented 108 days ago

Thank you, It easy to follow and it works.

Wei Commented 98 days ago

If you are sure about the data in origin is invalidate, you can use {git push -f -u origin master}to overwrite them.

Leave a comment