Git and GitHub

Photo by Yancy Min on Unsplash

Git and GitHub

Get Started with Git and GitHub

ยท

3 min read

Git

  • Git is a version control system and version control is the tracking and managing of changes to software code saving the history of software code.
  • Version control systems are software tools that help software teams and individuals to manage changes in source code over time.
  • this version control system gives the flexibility to revert to an older version of software code and keeps track of all updates which have been made to the software code. It keeps track of who changes It and when it is changed.
  • Contributing to opensource project git helps in which person made which change and where in the project all of this is recorded.

Starting with git basic commands

1) To make a new file

touch names.txt

2) To check if git is installed on your PC

git

3) To initialize an empty Git repository in your folder

 git init

4) To view the changes or the untracked files in the project that's not been saved yet or staged yet

 git status

5) Staging the files

 git add file_name or git add . (to stage everything in the current folder)

6) Committing the files

 git commit -m "your_message_here"

7) To unstage or remove a file from the staging level

 git restore --staged file_name.txt

8) To view the entire history of the project

 git log

9) Removing a commit from the history of a project (all the commits or changes before this will go back to the unstaged area now)

 git reset insert_commit_hash_id_to_which_you_want_to_go_back_to_here

10) when doing some changes in that software code base and we don't want to commit at least for now but we need it after some time and we want our software code the same as the last commit and changes after this made must be saved that can be done by stash.

 git stash

11) Bringing back those changes to the staging area or pop them from the stash

 git stash pop

12) To clear the changes or files in your stash( deleting all changes that were made in the stash).

 git stash clear

Git With GitHub

1) Connecting your Remote Repository to your Local Repository and GitHub repository URL needs to be pasted in insert_https_project_link_here

  • remote means you are working with URL
  • add means adding new URL
  • origin means the URL that you are going to add
git remote add origin insert_https_project_link_here

2) Pushing local changes to the remote repository

git push origin master (we're pushing to the url origin, and the branch master)

3) To view all your remote URLs

  • It show all your URL that is connected
git remote -v

Never commit on the main branch(Default branch is main branch) since it's the one used by the people, to prevent any mishaps because your changes might contain some error

4) Shifting the head to a branch (head is the pointer which points to where all you do your changes)

git checkout branch_name

5) Merging your branch to main of project

git merge branch_name

6) Then push all these local changes to your online repo

  • main is the branch

(Your code must go on the separate branch so the user is not affected)

git push origin main

7) Creating a new branch

git branch branch_name

Happy Learning ๐Ÿ˜€

ย