Git Command Guide
Git is a version control software designed by Linus Torvalds, thinking about the efficiency and reliability of maintaining application versions when they have a large number of code files.
Advantages:
โ๏ธ Better teamworkโ๏ธ Control of changes in the projectโ๏ธ Audit and reliabilityโ๏ธ Return to previous versionsโ๏ธ Local & Remotes Repositoriesโช๏ธ โช๏ธ โช๏ธ And much more
Download
Linux Debian:$ sudo apt-get install git
Linux Fedora:$ sudo yum install git
Mac
Windows
You can write the commands in your CMD or in the git bash terminal
About this Guide:
๐ Everything in bold means that the value is relative, it changes according to each one.๐ Is not a finished version.
โญ
Star the Project The easiest way you can contribute is by "starring" this project on GitHub! This will help you to "bookmark" the content so you can return to it. But it will also help the people who "follow" you on GitHub to discover that you find it interesting or useful.
The more people star and share the project, the more possible contributors are able to understand the value of contributing and open sourcing their knowledge!
I will be grateful that you follow me
๐
Commands ๐ต
GIT Version: git --version
โ
Set name credential: git config --global user.name "germancutraro"
โ๏ธ
Set E-mail credential: git config โ-global user.email โ[email protected]โ
Disable warning detached head:
git config --global advice.detachedHead false
๐
See all configurations: git config โ-list
๐
See own custom configurations: git config --list --global
๐
Help Command git help
๐
Get help from a specific command git help commit
๐
Create a Repository git init
๐ฅ
Delete a Repository rm -rf .git
๐
Add a file git add index.html
๐
Add multiple files git add index.html index.js
๐ฅ
Add all files git add .
๐
Add all the files in the current directory by their extension: git add *.txt
๐
Add all the files that are in a folder: git add css/
ใฝ๏ธ
Add all the files that were modified: git add -u
๐
Add all the files by their extension that are inside a folder: git add pdfs/*.pdf
๐ฆ
See modified files git status
๐ค
See the modified files without so much information: git status -s
๐
See the modified files and in which branch we are working: git status -sb
โ๏ธ
Delete a file that was in the staging area git reset index.js
โ
Delete a file that was in the staging area by their extension git reset *.xml
๐
Commit Changes git commit -m 'navbar created'
๐
See all the commits that we did git log
๐ฒ
See all the commits that we did in a pretty way git log --oneline --decorate --all --graph
๐ง
Create a Aliase/Shortcut git config --global alias.lg "log --oneline --decorate --all --graph"
So now we can do: git lg
for the pretty log command
Review of the basic and important commands
$ git init
-> Initialize a local Git Repository$ git add <file>
-> Add file to the Staging Area$ git status
-> Check status of files in the working branch$ git commit
-> Commit Changes$ git push
-> Push to Remote Repository
๐
See all the changes that happened between the working file and the staging file git diff
โญ
See all the changes that happened between the staging area file and the commited file git diff --staged
๐
Recover Files git checkout .
๐
Delete all the changes added in a file git checkout -- README.md
๐
Add files and commit in the same command: git commit -am 'README actualizado'
โ๏ธ
Edit the commit message git commit --amend -m 'We edited the message!'
Add or Back to the last commit โถ
git reset --soft HEAD^
โ๏ธ
Return to a specific commit in a weak way git reset --soft 39ae8e6
โฌ
๏ธ
Return to a specific commit in a hard way git reset --hard 39ae8e6
๐
List of originated commits git reflog
๐
Go back to a point git reset --hard 43809d4
โ๏ธ
Rename Files git mv index.js app.js
โ
Delete Files git rm app.js
Branches
A branch is basically a new timeline that stores commits. They are used to develop functionalities independent of each other. The master branch is the default branch when you create a repository. Create new branches during development and merge them to the main branch when you finish.
๐ฑ
Create a branch: git branch myBranch
๐
See the branches of our repository: git branch
๐ฟ
Work in a specific branch git checkout myBranch
๐
Create and move to a branch in a single command git checkout -b myBranch
Merge branches:
โ๏ธ
First we go back to the master branch: git checkout master
๐ป
And now we run the next command git merge myBranch
๐น
Once merged we can proceed to delete the branch git branch -d myBranch
Tags
Create a tag ๐ ๐ผ
git tag -a v1.0.0 -m "Version 1.0.0"
๐
Insert a tag in a specific commit git tag -a v0.1.0 43809d4 -m 'Alpha Version'
๐
See all Tags git tag
๐โ๐จ
See the tag message git show v1.0.0
โ๏ธ
Delete a tag git tag -d v0.1.0
Stash
๐ฆ
Creation git stash
๐ผ
Get the list git stash list
Github
๐ฎ
Once we create a repository, we can add it to the remote server: git remote add origin yourRepo.git
โฌ
See the remote sources of our repository: git remove -v
Once we have all our commits done and we have added the remote repository we can upload our files to Github:
โ๏ธ
Push: git push -u origin master
But, as you can see, the tags are not uploaded with the git push
command:
โถ๏ธ
Push the tags git push --tags
โ๏ธ
Ignore Files For this, you must create a .gitignore files, and there you can write the files and foulders that you dont want to upload to the github repository like:
node_modules package-lock.json
๐
Pull git pull
โ
Clone a Repository git clone repoUrl.git
๐
Clone a repository in a specific folder git clone repoUrl.git my-folder