what is Git?
Git is a version control system used for tracking changes, collaboration, and to push files to remote repository.
Then what the heck is github?
Github (Microsoft owned) is a service provided for git users to store our files(code) online which is called remote repo.
some of the popular alternatives to github are bitbucket and bitbucket.
Git workflow
simple workflow of a git
Initialize git in workflow directory -> add files to staging -> commit changes -> push to repo
you can do these things by learning the commands below :
Commands
SR.NO | COMMAND NAME | DESCRIPTION |
1 | git config –global user.email <email> git config –global user.name <name> | for first time you need to configure your name and email, to tell the git who is committing the changes to repo. |
2 | git init | “git init” is used to initialize local repo in our working directory. This is the first command to be used before any git command. |
3 | git status | “git status” will display the status of our files that include the untracked files , changes to be committed and the branch we currently working on. |
4. | git add | “git add .” will add all the files in our directory to staging. we can also use “git add <file_name> to add a specific file to staging |
5. | git rm -cached <file_name> | it is reverse command of “git add” . used to remove a file from staging. |
6 | git commit -m <message> | after staging it is used to commit with a message included of what we modified. |
7 | git log | displays all the commits you have made till now ( contains author of the commit , date of commit made) |
8 | git checkout <id> | “git checkout <id>” is a time-machine command used to go back to the previous commit |
9 | git revert <id> | git revert is used go back in time to one commit. |
10 | git reset [id] | “git reset –hard [commit_id]” is used to go back in time multiple times and stays there and discard the changes made after that. Note: messing with commit history of a repo is dangerous |
11. | git branch | it displays the branches present in your repo. |
12 | git branch [branch_name] | it create a new branch |
13 | git checkout [branch_name] | shifts from your current branch to the specified branch |
14 | git branch -d [branch_name] | will delete a specified branch |
15 | git merge [other_branch] | will merge the other_branch to the current branch you are in. |
16 | git clone [http_link] | git clone is how you get a local copy of an existing repository to work on |
17 | git remote add origin [link] | this command able to help us to connect the local repo to the github repository |
18 | git pull origin main | git pull(fetch+merge) is how you update that local copy with new commits from the remote repository |
19 | git push origin main | push the changes in your local repo (main brach) to the remote repo |
20 | git push origin –delete [branch_name] | used to delete a branch from a remote repo |