Git is a widely used version control system for tracking changes in source code during software development. It allows multiple developers to collaborate on a project without interfering with each other’s work.
Key Features:
Distributed System: Each developer has a complete copy of the project, enabling work to continue offline and providing backups.
Branching and Merging: Git makes it easy to create branches for new features or bug fixes, which can be merged back into the main codebase later.
Commit History: Changes are recorded as “commits,” allowing developers to review past changes and revert to previous versions if necessary.
Collaboration: Developers can push their changes to a shared repository, facilitating teamwork and version control.
Git simplifies the development process, enhancing efficiency and collaboration in coding projects.
Create repository
1
2
3
4
5
6
7
git config --global user.name "<name>"git config --global user.email "<email>"git config user.name
git config user.email
ssh-keygen -t rsa -C "<email>"git clone <url> #clone a remote repository with SSH protocol or HTTPS protocolgit init [folder]#initialize local repository
Modify and submit
1
2
3
4
5
6
git status #view statusgit add .
git rm <file>
git commit -m "<commit message>"git stash # store work space changesgit stash pop #
View submission history
1
2
git log
git log -p <file> #view the commit log of a given file
Revocation
1
2
3
4
5
6
7
git reset --hard HEAD
git reset --hard HEAD^
git reset --hard <commit>
git reset --soft <commit>
git checkout <files>
git restore <files> #revert the files in work spacegit restore --staged <files> #revert the files in staged files
Branches and Labels
1
2
3
4
5
6
7
8
9
git branch
git branch <new branch>
git branch -d <branch>
git branch -m <old branch name> <new branch name>
git checkout <branch>
git checkout -b <new branch> #build and switch to a new branch using the current branch as a prototypegit checkout -b <new branch> origin/<remote branch>
git diff <branch>
git cherry-pick <commit>
Mergers and Derivatives
1
2
3
git merge <branch>
git merge --strategy-option=theirs <other branch> #Force the merging of other branch into the current branchgit rebase <branch> #equal to <target branch> git merge <current branch>