In order to explore different commands in Git, you need to have a github account.
Follow the below link to create a new account in github.
https://help.github.com/articles/signing-up-for-a-new-github-account/
- Click on the new repository link and create a repo in Git.
-
Click the Create Repository button.
-
Once the repository is successfully created then the below page will be displayed.
-
Create a folder in your machine where you want to start using the new repository.
-
Follow the commands given below.
echo "# abc" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/dilipSundar/abc.git
git push -u origin master
- Congratulations , by completing the above steps you have successfully completed the pushing the code from your local to remote.
- Clone the repository
- Click on the clone or download button.
- Copy the link
git clone <copied-link>
- You have successfully cloned the repo. You can start working on that code.
git checkout -b <branch-Name>
-
Modify the code/file.
-
Run the below command to check the changed file.
git status
-
There are three steps to push the code to github.
- add
- commit
- push
-
Follow the below commands.
git add .
git commit -m '<change comments> '
git push origin <branch-name>
git pull origin <branch-name>
- Merging someother branch changes in to your branch.
git merge <branch-name>
Follow this link for the steps that need to be followed.
https://help.github.com/articles/fork-a-repo/
For Example:
If we want to stop ignoring the .idea folder then add the below line in the .gitignore file .
.gitignore file:
.idea/
Folder :
If the folder is already a part of the git repo then run the below command to remove it from the git repo.
The below command will remove the folder from the git repo.
git rm -r --cached <folder>
For Example : To remove the .idea folder run the below command.
git rm -r --cached .idea/
File :
If the file is already a part of the git repo then run the below command to remove it from the git repo.
git rm --cached <file>
Folder:
This will delete the untracked folder.
git clean -fd
The below command will unstage the staged files.
git reset HEAD
fatal: refusing to merge unrelated histories
- To solve the above issue we need to run the below command
git pull origin <branchname> --allow-unrelated-histories