Skip to content

hakxcore/learn_git_cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 

Repository files navigation

learn_git_cli

Please correct the mistakes if any 😇


Installation on Terminal

sudo apt-get install git

For other operating systems click here.



GIT COMMANDS


Git config

> git init #To initialize the dir to git
> git remote add origin <url to your github account> #to create a new repo
> git config --global user.name "name_of_user" #To register a user on github
> git config --global user.email "user_email@xyz" #To register an email address of the user
> git config --global core.editor Vim #To select a different test editor
> git config --global color.ui true  #You can customize your Git output to view a personalized color theme

--global

The global level configuration is user-specific configuration. User-specific means, it is applied to an individual operating system user.

--system

The system-level configuration is applied across an entire system. The entire system means all users on an operating system and all repositories. The system-level configuration file stores in a gitconfig file off the system directory.


Git creating a repository

> git init #To initialize a repository or dir to git
> git status  #check the status of git



Git staging the files

> git add newfile.txt #to add a new file to a repo
> echo "# Dubby Dubby Dub" >> README.md #Write text to file manually
> git add .
> git add --all
> git add -A
> git add <file-name>
> git add <file-name> <another-file-name> <and-another-file-name>
> git rm --cached <file-name>
> git reset <file-name>



Git pull and clone

> git clone <url to your repo> #To clone a repository form github
> git pull origin #To pull a whole doc or repo from github



Git push to push the repo to the remote server

> git remote add origin <link>
> git push origin #To push all the changes you have maked to the remote repo or to github
> git push origin -delete <branch name>   #You can delete a remote branch from Git desktop application.



Git branch

> git branch  <branch name> #create a new branch.
> git branch --list or  git branch  #list all branches
> git branch -d <branch name>  #Delete a branch.
> git checkout <branch name> #Git allows you to switch between the branches without making a commit.
> git branch -m master #Switch to master branch
> git branch -m <old branch name> <new branch name> #rename the branch with the help of the git branch command.
> git merge <branch name> #merge the other branch with the currently active branch.



Git commit and log

> git commit -m "Your message here" #commit for the file for changes
> git commit --ammend #Overwrite the previous commit
> git log --oneline #checkout the log history
> git log -1 #show top commit
> git log -2 #show 2nd commit from top
> git log --oneline #show all commits in oneline



Git stash and reset

> git stash #Stashing your work 
> git stash list #Stashed work's list
> git stash apply stash@(0) #reset the stash no (0)
> git add . #git add stashed data
> git commit -m 'message' #comitting your work
> git merge branch_name #merging the brances
> git push origin master #pushing the changes to the remote repository
> git stash clear #clear the stash
> git conflict #get solve the conflict
> git reset #reset(undo) change
> git reset --hard #reset(undo) all the changes



Git fetch and merge

> git fetch #to fetch all the changes madded in the local repo
> git merge #to merge all the changes maded

💡Suggested website: Gitexplorer

Credits

Copyright © 2021 by Hakxcore