Use of git remote code base

1. Install git

On most Linux systems, git is already installed and we can update it to the latest version with the following command.

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

 2. Create a remote repository

There are many remote code bases, you can choose one according to your preference. https://coding.net/ This is the coding market. Then register an account and create a new project.

3. Set up git

Before using it, we need to configure it so that git can track changes to project files. Set your username and email. It is best to match the username and email on your remote repository. 

git config --global user.name "your_username"
git config --global user.email [email protected]

Sets the push default to 'simple'.

git config --global push.default simple

4. Create a native codebase

Go to the root folder of your project. Enter the following command:

git init

git will create a hidden folder called .git inside your root folder, which is your local repository. 

To associate a remote repository, use the command git remote add origin git@server-name:path/repo-name.git;

After the association, use the command git push -u origin master to push all the contents of the master branch for the first time;

Thereafter, after each local commit, whenever necessary, use the command git push origin master to push the latest changes;

 

5. Load (stage) file

Now command git to load (stage) all the project files.

git add .

 If we only want to add specific files to source control, we can specify them.

git add my_file, my_other_file

 6. Submit documents

git commit -m "your changes"
git push

 If you want to see the status of loaded and unloaded files, commits, etc. The following commands can be executed:

git status

7. Create a branch

Create and switch to a new branch

git checkout -b new_feature

  Or you can create step by step, switch branches

git branch new_feature creates a branch
git checkout new_feature switch branch

 View all branches

git branch

 The branch with * is your current branch.

8. Merge branches

If you want to add your branch to the master branch. You need to load and submit your file:

git add . load file
git commit -m "merge branch" merge branch

Then move to your trunk branch:

git checkout master

  Then merge:

git merge new_feature

 This way your trunk branch will have the new features of your merged branch.

9. Delete the branch

First switch to your main branch master, and then enter the terminal (if the branch has been merged):

git branch -d new_feature

 If the branch is not merged, just enter:

git branch -D new_feature

 The capital D means forcibly delete the branch.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326894019&siteId=291194637