Languages: English | Portuguese
This repository was created to simplify and review the main commands used in GIT and what each of them is for!
After installing GIT and configuration your credentials, open Git Bash by right-clicking on your project folder and type the command below:
git init
To connect your local repository with the remote one:
git remote add origin https://github.com/username/repository.git
This link is just a example, replace with yours.
If you already have a remote repository, you can just clone this into your folder:
git clone https://github.com/username/repository.git
Before do a commit, you need add your new and change files to the staging area.
Adding just one file:
git add file_name
Adding a file that is in another folder:
git add folder/file_name
Adding all the files and changes:
git add .
To remove a file in the staging area (this not undo your changes in your real files project):
git restore -- staged file_name
If you want remove all them:
git restore -- staged .
To check which files is already in the staging and which is not in:
git status
What's in red is the files which is not in the staging area yet:
What's in green is the files which is in the staging area:
And if you don't have any files to add in the staging area:
To do a commit, which will prepare all the files in the staging area to be push late:
git commit -m "your message here"
Be careful when writing a message, be sure that you are explain what the commit is for.
To do a push to your remote repository:
git push -u origin nome_branch
To check all commits that you did:
git log
To update the last commit:
git commit --amend -m "your new message here"
To undo the last commit that was did without undo the changes in the staging area, just in the HEAD (which always point in the last commit):
git reset --soft
To undo the last commit in the HEAD (which always point in the last commit) and the staging area:
git reset --mixed
To undo the last commit in the HEAD (which always point in the last commit) and the staging area AND IN YOUR PROJECT:
git reset --hard
In case you and another person is working in the same project and you want get the changes that was did and update in your local repository:
git pull
To create a new branch:
git checkout -b branch_name
To swap to another branch already created:
git checkout branch_name
To check the last commit in each branch already created:
git branch -v
To delete a branch:
git branch -d branch_name
Before do a merge, check if you are in the branch that will receive the update. After that, type the command below:
git merge origin_branch