Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. This page contains a few useful git commands
Most common flow of commands
$ git add .
$ git status # Lists all new or modified files to be committed
$ git commit -m "Second commit"
$ git push -u origin master
- Create a repository on Github
- Go to your local project folder and git init.
git init
- Add README.md file using
echo "Hello" >> README.md
- Add
.gitignore
file manually and add the below content if your project is an eclipse maven project
# Eclipse
.classpath
.project
.settings/
# Intellij
.idea/
*.iml
*.iws
# Mac
.DS_Store
# Maven
log/
target/
- Add remote repository using
git remote add origin https://github.com/ayosuva/test.git
git remote add origin https://github.com/ayosuva/test.git
- create branch using
git branch -M master
git branch -M master
- Add
.gitignore
file alone usinggit add .gitignore
and then commit usinggit commit -m ".gitignore commit"
git add .gitignore
git commit -m ".gitignore commit"
- push the commits using
git push -u origin master
usegit pull origin master --allow-unrelated-histories
if you have initialized the repo in GitHub and also committed locally
git push -u origin master
git pull origin master --allow-unrelated-histories
- Now add the all others files using
git add .
– Adds all the files in the local repository and stages them for commit.
git add .
- commit using
git commit -m ".gitignore commit"
git commit -m ".gitignore commit"
- push the commits using
git push -u origin master
git push -u origin master
- To clone the existing report use git clone repository path
git clone https://github.com/ayosuva/SeleniumBDD.git
- To pull the latest code from the current repo
git pull
- To know the git version
git --version
- To add and list git config
$ git config --global user.name "YOUR_USERNAME"
$ git config --global user.email "atest@test.com"
$ git config --global --list # To check the info you just provided
- To see what files are staged
git status
- Uncommit Changes you just made to your Git Repo
$ git reset HEAD~1
# Remove the most recent commit
# Commit again!
18. See the Changes you made to your file
$ git diff # To show the files changes not yet staged
19. Revert back to the last committed version to the Git Repo
$ git checkout .
OR for a specific file
$ git checkout -- <filename>
20. View Commit History
$ git log