BASIC GIT COMMANDS
Basic Configuration
Configure Name that appear in commits
git config --global user.name "Name"
Configure Email
git config --global user.email email@gmail.com
Color frame for commands
git config --global color.ui true
Starting repository
We start GIT in the folder where the project is
git init
We clone the github or bitbucket repository
git clone <url>
We add all the files for the commit
git add .
We make the first commit
git commit -m "First commit"
we go up to the repository
git push origin master
GIT CLONE
We clone the github or bitbucket repository
git clone <url>
Clone the github or bitbucket repository ?????
git clone <url> git-demo
GIT ADD
We add all the files for the commit
git add .
We add the file for the commit
git add <file>
We add all the files for the commit omitting the new ones
git add --all
We add all files with the specified extension
git add *.txt
We add all files within a directory and a specific extension
git add docs/*.txt
We add all files within a directory
git add docs/
GIT COMMIT
Upload changes made to the HEAD
git commit -m "First commit"
Add and load changes made to the HEAD
git commit -a -m "Last commit"
If there are conflicts, it shows them
git commit -a
Add to the last commit, this is not shown as a new commit in the logs. You can specify a new message
git commit --amend -m "Last commit"
GIT PUSH
We go up to the repository
git push <origien> <branch>
We go up tag
git push --tags
GIT LOG
Show commits logs
git log
Show changes in commits
git log --oneline --stat
Show commit graphics
git log --oneline --graph
GIT DIFF
Shows the changes made to a file
git diff
git diff --staged
GIT HEAD
Remove a file from the commit
git reset HEAD <file>
Returns the last commit that was made and puts the changes in staging
git reset --soft HEAD^
Return the last commit and all changes
git reset --hard HEAD^
Returns the last 2 commit and all changes
git reset --hard HEAD^^
Rollback merge/commit
git log
git reset --hard <commit_sha>
GIT REMOTE
Add remote repository
git remote add origin <url>
Change remote
git remote set-url origin <url>
Remove repository
git remote rm <name/origin>
List of repositories
git remote -v
Show remotes branches
git remote show origin
Clean all deleted branches
git remote prune origin
GIT BRANCH
Create branch
git branch <nameBranch>
List of branches
git branch
-d command removes the branch and joins it to the master
git branch -d <nameBranch>
Delete without asking
git branch -D <nameBranch>
GIT TAG
List of tags
git tag
Create new tag
git tag -a <verison> - m "version x"
GIT REBASE
The rebase is used when working with branches this causes the branches to be updated with the master without affecting it.
Join the current branch with the mastar, this cannot be seen as a merge
git rebase
When a conflict occurs you do not give the following options:
when we resolve conflicts — continue the sequence of the overflow where it was paused
git rebase --continue
Skip the conflict and go your way
git rebase --skip
Return everything at the beginning of the rebase
git reabse --abort
To rebase a specific branch
git rebase <nameBranch>
GIT DIFF
The Diff command is used to visualize the differences between objects (branches, commits, files, among others).
Show files that are not in the repository in the current branch
git diff
Show the differences between commits
git diff 1234abc 6789def #old new
It shows the differences of files of the “staged area”
git diff --staged
Show the differences between branches
git diff branch1 branch2
Show the differences in a specific file
git diff myfile.txt
Show files with changes in a directory
git diff documentation
OTHER COMMANDS
List a current state of the repository with a list of modified or added files
git status
Remove a file from the HEAD and put the unworked status
git checkout -- <file>
Create a branch based on one online
git checkout -b newlocalbranchname origin/branch-name
Search for new changes and update the repository
git pull origin <nameBranch>
Change branch
git checkout <nameBranch/tagname>
Match the current branch with the specified one
git merge <nameBranch>
Verify changes in the online repository with the local
git fetch
Delete a repository file
git rm <file>
Save local modifications temporarily
git stash
Fork
Download remote from a fork
git remote add upstream <url>
Merge with a fork master
git fetch upstream
git merge upstream/master