banner
keney

keney

remain optimistic
twitter

Git commit local code to branch (detailed step by step)

View Branches#

A: View Local Branches
Use the git branch command, as follows: git branch
The branch marked with * is the branch you are currently on.

img

B: View Remote Branches

The command is as follows: git branch -r

img

C: View All Branches

The command is as follows: git branch -a

img

  1. Create a New Branch Locally

The command is as follows: git branch [branch name]

For example: git branch plateformSuperdog

  1. Switch to the New Branch

The command is as follows: git checkout [branch name]

For example: git checkout plateformSuperdog

  1. Create and Switch Branch

The command is as follows: git checkout -b [branch name]

For example: git checkout -b plateform2

In this case, git checkout -b [branch name] is equivalent to two steps:

git branch [branch name]

git checkout [branch name]

  1. Push the New Branch to GitHub

The command is as follows: git push origin [branch name]

  1. Delete Local Branch

The command is as follows: git branch -d [branch name]

  1. Delete Remote Branch on GitHub

The command is as follows: git push origin :[branch name]

In this case, the colon before the branch name represents deletion.

For example: git push origin :plateform2

  1. Commit Local Code to New Branch in Git

  2. Switch to the new branch

The command is as follows: git checkout [branch name]

For example: git checkout plateform2

  1. Add the code to be committed locally

The command is as follows: git add .

  1. Commit the local code

The command is as follows: git commit -m "modification description"

  1. Push to the Git repository

The command is as follows: git push origin [branch name]

For example: git push origin plateform2


Summary:#

  1. Clone the repository:
git clone [ssh repository address]
//cd into the repository
cd folder name (cloned folder)
  1. Copy the code to be committed to the repository (cloned folder)
//Create a branch
git branch branch name

//Push the branch to the remote repository
git push origin branch name

//Switch to the desired branch
git checkout branch name

//Commit the code to the desired branch
git add ./
git commit -m "code committed"
git push

//or
git push origin branch name

Note: This requires binding a GitHub account.

Merge Branches#

https://blog.csdn.net/chenyao1994/article/details/114686758

Git Merge Branch (Easy to Understand)

Suppose we are on the dev branch and have just finished developing a project. We execute the following commands:

git add .
git commit -m 'commit message'
git push -u origin dev

To merge the dev branch into the master branch, follow these steps:

  1. Switch to the master branch
git checkout master
  1. If it is a collaborative development, pull the code from the remote master
git pull origin master
//If you are the only developer, there is no need. For safety, it is recommended to pull.
  1. Merge the code from the dev branch into the master branch
git merge dev
  1. Check the status and execute the commit command
git status

On branch master
Your branch is ahead of 'origin/master' by 12 commits.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

//This means you have 12 commits that need to be pushed to the remote master.
> Finally, execute the following commit command:
git push origin master
  1. Other commands
Update the list of remote branches
git remote update origin --prune

View all branches
git branch -a

Delete the remote branch Chapater6
git push origin --delete Chapater6

Delete the local branch Chapater6
git branch -d  Chapater6

Attachment#

*GIT Development Learning - Several Methods for Merging Branches*#

https://blog.csdn.net/fenglolo/article/details/125223433

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.