Post

GIT

What is the Git terminal? At its core, Git is a set of command line utility programs that are designed to execute on a Unix style command-line environment. Modern operating systems like Linux and macOS both include built-in Unix command line terminals. This makes Linux and macOS complementary operating systems when working with Git. Source: atlassian.com

Getting started with git:

If you are on any linux distro you can use the package management tool that comes with your distribution to install it.

└─$ sudo apt install git-all

Git configuration

  • Setting up your username and email
1
2
3
└─$ git config --global user.name "your username"

└─$ git config --global user.email "youremail@email.com"
  • Saving your git token locally
1
└─$ git config --global credential.helper store

Starting a project

1
2
3
4
5
└─$ git init

└─$ git init <directory>

└─$ git clone <url>

Making changes

  • Stage a single file
    1
    
    └─$ git add <file name>
    
  • Stage all files
    1
    
    └─$ git add .
    
  • Commit all staged files
    1
    
    └─$ git commit -m "your commit message"
    
  • To remove file from staged area
    1
    
    └─$ git rm --cached "file_name"
    
  • Remove file
    1
    
    └─$ git rm <file name>
    

Branches

  • Creating new branch
    1
    
    └─$ git branch "branch_name"
    
  • Listing all local branches
    1
    
    └─$ git branch -a
    
  • Creating and switching to another branch
    1
    
    └─$ git checkout -b "branch_name"
    
  • Switching to another branch
    1
    
    └─$ git checkout "branch_name"
    
  • To delete/remove a branch
    1
    
    └─$ git branch -d "branch_name"
    
  • Deleting a branch whether merged or not
    1
    
    └─$ git branch -D "branch_name"
    
  • To push your branch
    1
    
    └─$ git push --set-upstream origin "branch_name"
    

    Remote updates

  • To list remotes
    1
    
    └─$ git remote -v
    
  • To show information
    1
    
    └─$ git remote show "remote_name"
    
  • To add remote
    1
    
    └─$ git remote add "path/url"
    
  • To fetch changes from remote repo(no merge)
    1
    
    └─$ git fetch "remote_name"
    
  • To fetch from specific branch
    1
    
    └─$ git fetch "remote_name" "branch_name"
    
  • To fetch and merge
    1
    
    └─$ git pull "remote_name" "branch_name"
    
  • To push local to remote
    1
    
    └─$ git push "remote_name "branch_name"
    
  • To delete remote branch
    1
    
    └─$ git push remote :branch
    

    Merging

  • To merge into current branch
    1
    
    └─$ git merge "branch_name"
    
  • Merge tool to resolve conflicts
    1
    
    └─$ git mergetool
    
  • Rebase into branch
    1
    
    └─$ git rebase "branch_name"
    

    Pulling and pushing

  • Upload all staged files
    1
    
    └─$ git push
    
  • Upload content to remote
    1
    
    └─$ git push "remote_name"
    
  • Upload to a branch
    1
    
    └─$ git push "remote_name" "branch_name"
    
  • Fetch and merge remote repo’s copy
    1
    
    └─$ git pull
    
  • To move your local changes to the latest changes made to remote repo(rebase)
    1
    
    └─$ git pull --rebase "remote_name"
    
This post is licensed under CC BY 4.0 by the author.