-
Notifications
You must be signed in to change notification settings - Fork 0
N6_Git and Github_version control
- Goto the official website of Git to download git Click here.
- Installation on windows comes with "Git Bash" terminal.
- Can use "powershell" or cmd terminal from windows too.
- Can use "hyper.is" which works across all platforms.
You need to configure your name, your email address and default branch to know who is doing the change
git config --global user.name "type your name w/ quote"
git config --global user.email <type your email address w/o quote>
git config --global init.default branch main
- To clone:
git clone https://github.com/user-name/repository.git
- To pull first
git init or git init repo-name
and thengit pull https://github.com/user-name/repository.git
- option 1: Go to the project directory in your PC and open git bash there.
- option 2:
$cd /c/Users/project
- option 3:
$cd "C:\\Users\project"
- goto the specific dir from the cmd (cd or cd.. is to navigate to different folder):
mkdir "name of the folder"
- cd to be inside that dir. make a sample .txt file.
- Make a .git folder to track the changes
git init
. Before or after this command you can list all your folderdir
ordir \ad
note: ideally this command isls
orls -a
. A.git
file will be created -
git status
(To check if the files are being tracked or not) -
git add .
orgit add <file.txt>
(to track and update the changes) -
git commit -m "message"
(a specific message to see what the changes are you made to your files" > it tracks every changes you make. -
git remote add origin "https://githubfolder"
(to sync with github repository. Before this you need to create a github repository) -
git push origin master
(at this stage you need to use your ssh keys passphrase or other security pass for the first time). Be careful about the current branch you are working and the github branch you want to push. -
git log
(summarize all changes until) - to revert last git commit
git revert <alphanumeric code from git log>
- To set the default branch as main do the git config command
git config --global init.default branch main
and run VScode afterwards (did not work for my case and faced a lot of issues!!!!) - The second option was to set the current master branch as main and delete the master branch. Follow the steps
- rename your local branch:
git branch -m master main
- change the tracked branch:
git fetch -p origin
and thengit branch -u origin/main main
- change the main local branch:
git remote set-head origin -a
- optionally, remove the master branch, local and remotely:
git branch -D master
and thengit push origin :master
When I was working with cloud shell, I got stuck with authentication for github.It was asking for password and when I was entering the pass it got denied. I was looking at different solutions that are provided online. I have found the following documentation useful for my understanding on different types of authentication methods (https://docs.github.com/en/authentication)
For me, I have solved my problem by creating and using SSH keys for my windows (from local cmd). To create SSH I have followed the below command:
-
Make sure you are in the .ssh directory from cmd where you want to generate the ssh key (https://www.howtogeek.com/762863/how-to-generate-ssh-keys-in-windows-10-and-windows-11/)
-
ssh-keygen > Generating public/private rsa key pair. > Enter file in which to save the key (C:\Users\tahsi/.ssh/id_rsa): (you can press enter to use the default path or can set a new one) > Enter passphrase (empty for no passphrase): (This is by far the most important part. While typing you cannot see the character but need to memorize or store the pass phrase) > Finally, you have created an id_rsa type ssh key on your local machine! But I don't know why it cannot be added on github! or, 2. ssh-keygen -T id_ed25519 -C "[email protected]" it will create an id_ed25519 type ssh key locally.
-
Now you have to add the ssh key to your github account. Goto ssh key>add new key>enter the 20-char key
-
From your computer, goto settings>apps>optional features>OpneSSH client installed
-
Goto: services>OpenSSH authentication agent>properties>automatic(delayed) this setting enable the ssh key from the startup. Do not need to enter credentials each time you restart your PC (https://stackoverflow.com/questions/18683092/how-to-run-ssh-add-on-windows)
-
from cmd: start-ssh-agent > the agent will find the ssh and add it. Need to enter the passphrase here.
Now you can easily push your local directly to your github account
git remote add origin "https URL"
git push origin master
- Not sure which command is for what? type the following command for help on git config
git config -h
. Or for details typegit help config
- To clear windows type
clear
and press enter (In git bash). For cmd terminal typecls
and press enter
- Manual for Git git manual
- YouTube tutorial link