New Repository
Local directory, create a new Code warehouse (repository) on the command line
There's only one readme.md.
The command is as follows:
Touch readme.md
Git init
Initialize Repository
git add readme.md
Add readme.md to the buffer
(You can use git add--a to commit all changes to the cache (note that two bars))
Git commit-m "First commit"
Submit a change with the submit message "first Commit"
Push
git remote add Origin Https://github.com/XXX (username)/yyyy (projectname). Git
Add a remote address called origin, and the address is on GitHub (Create a new repo will be available)
Because Git is distributed, you can have multiple remotes.
git push-u Origin master
Push local content to the address on GitHub.
Parameter-u
After using the parameter-u, you can pull directly from the previous push to the branch with the git pull without parameters.
At this point, if there are some commits that are not locally on the master branch of origin, push fails.
So the workaround is to first set up the upstream branch of the local master:
git branch--set-upstream-to=origin/master
Then pull:
git pull--rebase
And finally push:
git push
Branch
The new code base has only one main branch (Master) and it is built automatically.
You can create a new branch for development:
git branch Develop master
Create a new branch called develop, based on the master branch
Switch to this branch:
git checkout Develop
You can now make some changes on this develop branch and commit.
Note : When switching branches, it is found that the contents of the files in the Repository folder in Windows are changed in real time and become the contents of the current branch.
Push Method 1:
Now, if you want to push the contents of this develop branch directly to GitHub,
git push-u Origin
If this is the first push of the new branch, you will be prompted:
Fatal:the Current Branch develop have no upstream branch.
To push the current branch and set the remote as upstream
git push--set-upstream origin develop
Enter this line of command, then enter the user name and password, and the push succeeds.
Subsequent push will only need to enter the git push Origin
Push Method 2:
A new branch called Dev, for example, is not available on the GitHub site and can be directly:
git push-u origin dev
Such a new branch is created.
Push Method 3:
There are several branches submitted to GitHub, which can be used in such a format:
git push-u origin local:remote
For example:git push-u origin master:master
Indicates that the local master branch (before the colon) is push to the master branch of GitHub (after the colon).
If the left side is not empty, the remote right branch will be deleted.
Another way to create a branch
Use the command git checkout-b develop2 develop
You can create a new branch DEVELOP2 and switch to this branch
Delete Branch
git branch You can view all the branches
git branch-d develop2 Remove the DEVELOP2 branch
Clone
Using the Git Clone+github address method, the project defaults to only the master branch. git branch is only master
To see all the branches:git branch-a or git branch-r
This is the time to create a new branch called Dev, based on the remote Dev branch:git checkout-b dev origin/dev
Add tag
git tag tagname develop
git tag has two parameters, one is the label name and the other is the point where you want to tag the develop branch.
Merging branches
git checkout Master
Go to Main branch first
git merge--no-ff develop
and merge the develop branch.
Parameter meaning:
By default, a fast-forward merge is performed without parameters.
With the parameter--no-ff, a normal merge is performed and a new node is generated on the master branch.
If you encounter a conflict in the merge, manually resolve it and then add,commit again.
Remotely manage projects in Git