Git is an example of a distributed version control system commonly used for open source and commercial software development.
Let's go :
- Initalize git in files/directories.
git init
- Clone the repository in your local system.
git clone https://github.com/<your-user-name>/<repo-name>
- To check the current status of the repository.
git status
- To add a specific file to the staging area.
git add <file-name>
- To add all changed file to staging area.
git add .
- To unstage a certain file
git restore --stagged <filename>
- To see recent changes in the repository.
git diff
- To give a message and commit.
git commit -m "your-message"
- To see the commit history.
git log
- To see last specific commits (eg. Last 3 commits).
git log -3
- To discard the specific commit.
git revert <commit-token>
- To undo the commit and bring back changes to staging area.
git reset --soft HEAD <no._of_commit_to_revert>
- To show remote URLs
git remote -v
- To fetch the changes from origin to your local system.
git pull origin
- To create a branch named branch-name.
git branch <branch-name>
- To make changes in the specific branch.
git checkout <branch-name>
- To merge sub branch to main branch.
git merge <branch-name>
- To delete a specific branch.
git branch -d <branch-name>
- To push the recent commits.
git push origin <branch-name>
- Connect to remote
git remote add origin <url>
- To push the current branch and set the remote as upstream
git push --set-upstream origin master
- To rename branch name.
git branch -m <branch-name>
ย