git tutorial

Vocab

  • Repository (or repo) = Project
  • Working directory = Location of the project
  • Stag or Stagging = prepare or makeing ready ( It is done before commit)
  • Commit = Save in my computer in git history (When we push, all the file will be upload if it is commited)
  • push = Saving file to the remote directory (Only the committed file will be uploaded)
  • pull = Update local repository from the server
  • clone = copy. copying a remote repository from internet at beginning
  • master = Consider the git repository as a tree. The tree has body and branch. master is the body of the branch.
  • github, bitbucket = they hosts my repository but git is not equal github.

Daily work flow

Add/Edit file - Stag - Commit - Pull - Push
General steps:
  1. Create a folder in you computer. Suppose it's name is learningWordPress.
  2. Create a repository in your github.com account with a readme. Suppose the name of this repo is learningWordPress. Now, it's link will be https://github.com/rejauldu/learningWordPress.
  3. Go into the learningWordPress folder and run the following commands.
git init
git add .
git commit -m "Initial Commit"
git remote add origin https://github.com/rejauldu/learningWordPress
git pull origin master --allow-unrelated-histories
git push origin master
Finished.

Introduction and commands

1. Donwload & Install git from https://git-scm.com
2. After installation open ‘Git Bash’ which is the command line write the following commands
Name and email
git config --global user.name 'Rejaul'
git config --global user.email 'rejaul@gmail.com'
Desc: git tracks all the changes in any file of the repo and tracks who has changes that file. To track this change this name and email is required.
Git initialization
git init
Check if not committed
git status
Staging
git add index.html
or to add all files:
git add .
Commit
git commit -m 'This is my first commit'
Backup
git checkout -- .
Add a github repo
git remote add origin https://github.com/rejauldu/travel-site.git
Push to server
git push origin <your_branch_name>
Clone
git clone https://github.com/rejauldu/travel-site.git
Pull
git pull origin <your_branch_name>
Fetch
git fetch origin <your_branch_name>
Note: When you want to download a new branch from remote to local, you should fetch this branch. When you fetch a new branch, then execute checkout command to change directory.
Merge
git merge <your_branch_name>
Rebase
git rebase <base>
See local branch
git branch
See remote branches (sometimes it does not show all branches for few system)
git branch -r
Change branch
git checkout <your_branch_name>
Delete branch
git branch -d <your_branch_name>
Server address
git remote -v
Setting new server after clonning
git remote set-url origin https://github.com/rejauldu/travel-site.git
GitLab remote: HTTP Basic: Access denied and fatal AuthenticationGo to Windows Credential Manager (press Windows Key and type ‘credential’) to edit the git entry under Windows Credentials. Replace old password with the new one.

Forcefully push

git push origin <your_branch_name> -f

Revert to a previous commit

  1. Go to the remote repo (github, gitlab, bitbucket) and find the number (ie. 6855d0f) associated with the commit.
  2. Run the command (in local machine): git checkout 6855d0f

Merge vs Rebase

অন্য ব্রাঞ্চের ফিচার মেইন ব্রাঞ্চে আনতে মার্জ করতে হয়।

মেইন ব্রাঞ্চের ফিচার অন্য ব্রাঞ্চে নিতে রিবেজ করতে হয়।

সতর্কতাঃ

  • Commit কমান্ডের পর pull করা যাবে না। তাহলে রিজেক্টেড হবে। যদিও নতুন কোন কমিট কেউ না করে থাকে তবুও পুল হবে না। ফোর্স পুল করলে এই কমিটের সব হারিয়ে যাবে।
  • রিজেক্টেড দেখানোর পর ভুল করে ফোর্স পুল করলে ক্যান্সেল করার উপায়ঃ git reset --hard main@{1} এখানে main হলো ব্রাঞ্চ নেইম।

How to change the interface of gitbash

  1. Locate the Git installation folder on your computer. (ie. Program Files/Git)
  2. Make a backup of the git-prompt.sh file in Git’s etc\profile.d subfolder.
  3. With administrator rights, edit the properties in the file named PS1. Use # to comment
  4. Save the git-prompt.sh file.
  5. Open a new Git Bash Shell prompt to see the customized properties display.

Labels: ,

© copyright-2020 Rejaul