Creating a local git repo
- Go to the folder where the files are and first create a git repo: git init
- Add what ever file that needs to be backed up: git add xxx.py
- Once you have made the necessary changes, then commit: git commit -m "Added multiple equipment"
- when no seperate branch is created, you get one branch called master
- When change is required, we branch off- create a new branch: git checkout -b
- once checked out, the git points to the new branch. Any commits will go to the branch. Always look for: git status
Uploading your local repo to the remote
- To create a new online github repo: git remote add origin url
- origin - is the name of the tool (choose anything). url - get the https url from the github page after you create it
- Then use git push to submit, git pull to download from the repo
- They have stopped authentication using password- forcing us to use another software for authentication.
- Alternately, you can use SSH.
- For this, you need to first create a ssh key - ssh-keygen -o -t ed25519 -C "emailid"
- The email id is the id used in the github
- Now, you have to save the file in .ssh/id_xxx. ensure that the file is linked to git hub in ~/.ssh/config
- It should have the folloing lines-Host github.comAddKeysToAgent yesIdentityFile ~/.ssh/id_ed25519
- check if the ssh works by typing git -vT git@github.com
- Now connect the local git to the appropriate remote hub. git remove add
- Be careful about the branch name. In my mac version, the default branch when you add a file using git add in local mode is master. But I think they are changing it to main or something like that
Finally, when you want to push the local files to the github, do git push
Maintainance of a code - branching
- When you are modifying a code, you need to move away from a working code. So, you branch out frm master brach. You checkout and branch by git checkout -b
- Now all commits will go only to the new branch and not to the master code.
- If in between, you want to create another branch to the master code, then you need to checkout the master first - git checkout and the create a new checkout git checkout -b
- At whatever time, once the changes are done and you want to incorporate the new code changes to the master branch. This is done by first checking out master git checkout master, then you merge this with the new branch you want to merge - git merge , follow it with commit and then push.