Getting Started with GitHub
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning-fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.
-From Git official WebSite-
Basic Git Commands
git add <file_name>
Add the changes you have done to the software code to the "Staging Area". This command includes all the changes you have done to the file and makes the file ready for the commit stage.
git commit -m<"commit_message">
This will save the changes you have made to the file. Here Git take a snapshot of the current version of the code of you and save it. In case you will be able to come back to this version of your code if necessary. Here commit message should be very precise about the changes you have made to the code file.
git clone <repository_url>
Create a copy of a remote repository in your local computer
git fork
Create a copy of a another remote repository in your remote repository. (Create copy of some other user's repository in your GitHub account)
git init
Git init create a local git repository in your working directory. If you want you use Git in your project firstly you have to initialize a git repository using "git init" in your working directory.
git push
Push the local repository in to the remote repository. It will upload the files in your local working repository to the remote repository.
git pull
Get the newest changes of the remote repository to your local repository. If there is any update to the remote repository it willl added to your local repository when use git pull.
git branch <branch_name>
Create a new branch in your Git repository
git checkout <branch_name>
Shift to the new branch which is already created
git checkout -b <branch_name>
This will create a new branch and shift to that branch.
git merge
Combine two branches and make them a single branch
git remote add origin <repository_url>
This Command add a remote repository to your local repository. This connects your local repository with your remote repository.
git revert
Go to a previous snapshot/ previous stage of your code in case of undoing the situation.
git log
Shows all the previous commits you did to your repository.
Start working with New GitHub Repository
- Create a new repository in your working directory using "git init"
- Create a remote repository in GitHub(You can use other Online Platforms as your choice) and copy the repository URL.
- Using this command "git remote add origin <repository_url>" connects your remote repository with the local repository.
- Create the main branch in the GitHub repository using the "git branch -M main" command.
- Then you can push your files to GitHub using the "git push -u origin main" command.
Start working with Existing GitHub Repository
- Open Git Bash in the directory you want to save the files.
- Using the "git clone <repository_url>" command you can clone the existing GitHub repository to your working directory.
- Now you can move to that directory and edit the files in that repository.
- After changes, you can stage your work with "git add <file_name>" or "git add ." (This add all the files in that directory to the staging area")
- The using "git commit -m<"commit_message"> " you can commit the changes you have done to the files.
- Finally using "git push" you can push the updated files to the remote repository.
Update the Local Repository from Remote Repository
- Use "git pull" to get the latest snapshot of the remote repository to your local repository.
- Then you can work with those updates.