GIT use notes
1. Create a server git repository git init --bare
Creating a repository directory as a server, such as server
cd server
git init --bare
cd ..
sudo chmod -R a+w server
2. Cloning a remote server in the local repository git clone
Local warehouse assume named local
sudo git clone [email protected]:/Users/zjq/githome/server local
After execution, the following message appears:
warning: You appear to have cloned an empty repository.
Checking connectivity... done
cd local
ls -al
We can see .git directory, indicating the local warehouses have been cloned generation.
3. Submit git add files to the staging area
Create a new file, for example f01.c
sudo vim f01.c
Then execute
git status
You will see the following prompt
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# f01.c
nothing added to commit but untracked files present (use "git add" to track)
Excuting an order
sudo git add f01.c
git status
You will see the prompt has changed, as follows:
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: f01.c
4. The staging area is already in the file submitted to the local repository. git commit
F01.c front of the file has been submitted to the staging area, and then execute the following command:
sudo git commit f01.c -m "f01.c"
After the execution, a message appears:
[master (root-commit) 843f55f] f01.c
1 file changed, 1 insertion(+)
create mode 100644 f01.c
And then execute the command
git status
Tip information:
# On branch master
nothing to commit, working directory clean
5. Submit to the remote server repository git push
The warehouse will continue to submit local repository files to the server side, origin represents the remote server, master represents the local current branch warehouse, execute the command:
sudo git push origin master
After the execution message:
Counting objects: 3, done.
Writing objects: 100% (3/3), 204 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/Users/zjq/githome/server
* [new branch] master -> master
6. Review the local branch warehouses and remote repository git branch
Check local branch warehouse, execute the command:
git branch
Display message:
* master
master branch name, branch in front of the * denotes current work.
View remote server-side warehouse, execute the command:
git branch -r
Display message:
origin/master
7. Create a new branch git branch new branch name
In the current branch node, create a new branch, the command:
sudo git branch branch001
That created a branch called branch001, you can view with the git branch command.
In each create a new branch of the time, the most current version of the branch's work at that time which will serve as the starting point of a new branch built version, that version of the new branch of the old from the latest version of the branches start.
8. The handover branch git checkout
Handover branch, the command:
sudo git checkout branch001
The current work is about to switch to a branch branch01.
9. merging branches git merge
Merge branch to the main branch branch001 master, a command to switch to the checkout using the first master, and then merge merge command:
sudo git checkout master
sudo git merge branch001
If there is a conflict, you will be prompted to call git status to view the file conflict.
Conflict resolution, and then call git add the file to solve scratch.
After all conflict resolution, git commit to commit the changes.
10. Remove the branch git branch -d name to be deleted branches orgit branch -D branch name to be deleted
Execute git branch -d <branch name>
If the branch is not merged into the master branch will complain, you can use the following command to force delete git branch -D <branch name>
sudo git branch -d branch001
sudo git branch -D branch002