Github help web page: https://docs.github.com/en/github
Git help web page: https://git-scm.com/book/en/v2
There are three stages to keep youre codes.
- A: Local codes (in your PC)
- B: Local branch in the local repository (in your PC)
- The local repository also keeps all the history of the code changes occurred in your PC.
- C: Remote branch in the remote repository (in the github web page: https://github.com/simonsobs/wire_grid_loader)
If you want to save your change of the codes in the remote, you need to do 3 steps.
- Change your code locally in A.
- Add and commit your change in the local branch(B).
- Push your change in the local branch to the remote branch(C).
You can create multiple branches in B and C.
However, usually you just need to use master
branch.
Ref.: https://docs.github.com/en/github/using-git/using-common-git-commands
-
Add your files to be updated to the local branch (B)
(to add all the files in the current directory)git add .
or (to add a spefic file)
git add <FILE NAME>
-
Update the changes to the local branch (B) with a comment
git commit -m "<COMMENT>"
or
git ci -m "<COMMENT>"
(
ci
is an alias ofcommit
) -
Update the changes from the local branch (B) to the remote branch (C)
Ref.: https://docs.github.com/en/github/using-git/pushing-commits-to-a-remote-repositorygit push
or
git push <REMOTE NAME> <LOCAL BRNCH NAME>
Usually,
<REMOTE NAME>
(C) isorigin
, and<LOCAL BRANCH NAME>
(B) ismaster
.
In this case, the master branch in B is uploaded to the master branch in C.
Ref.: https://docs.github.com/en/github/using-git/getting-changes-from-a-remote-repository
Shortcut command:
-
Get the changes in the remote repository (A) and merge it into your local master branch (A)
git pull
or
git pull <REMOTE NAME> <REMOTE BRANCH NAME>
Usually,
<REMOTE NAME>
isorigin
, and<REMOTE BRANCH NAME>
ismaster
.
The push
command does the following 2 steps;
-
Get the remote changes
git fetch
or
git fetch <REMOTE NAME>
Usually,
<REMOTE NAME>
isorigin
. -
Merge the changes in remote repository (C) into the local branch (B) (current local branch)
git merge <REMOTE NAME>/<REMOTE BRANCH NAME>
- The data of the remote repository is kept also in your PC when you fetch it. The remote repository in your PC is not edited.
-
Check only the local branch (B)
git branch
-
Check the remote branch information (C)
git remote -v
-
Check the local and remote branches (B & C)
git branch -a
- This command shows the information of the remote branches fetched into your PC.
-
retrieve remote branch
git checkout -b <NEW BRANCH NAME> -t <REMOTE NAME>/<REMOTE BRANCH NAME>
- Usually, we use the same branch name between (at local) and (at remote).
- The is usually
origin
-
After retrieving the remote branch, you are at the new branch at local
git log
git status
git reflog
-
Create branch
<BRANCH NAME>
git branch <BRANCH NAME>
-
Move to the branch
<BRANCH NAME>
git checkout <BRANCH NAME>
-
Create and move to a new branch
<BRANCH NAME>
git checkout -b <BRANCH NAME>
-
Push only the local branch
<BRANCH NAME>
to the remote<REMOTE BRANCH>
git push origin <BRANCH NAME>:<REMOTE BRANCH>
Usually, remote branch name is same as the local branch name
<BRANCH NAME>
.
-
Check remote branch
git branch -a
origin/aaaa is a remote branch
-
Create the new branch (
<LOCAL BRANCH>
) at the local from remote branch<REMOTE BRANCH>
(aaaa)git checkout -b <LOCAL BRANCH> origin/<REMOTE BRANCH>
-
Set an upstream remote branch to
origin/<REMOTE BRANCH>
git push --set-upstream origin <REMOTE BRANCH>
or
git push -u origin <REMOTE BRANCH>
-
Get update in the remote repository
git fetch --all
-
Reset working directory/index(added materials)/HEAD(position of local repository) to the origin/master
git reset --hard Origin/master
-
Update the working directory/index/HEAD to the updated remote repository
git pull
-
check the all the actions at the local
git reflog
-
go back to the condition right before the
<HEAD>
action<HEAD>
looks like ex)"f55cb888" or ex)"HEAD@{0}" in the reflog outputgit reset --hard <HEAD>
--hard means the local files(A) also will be changed. Without --hard, the change is occurred only in the local repository(B).
git rm -r --cached <file name>
git restore --staged <file name>
Here, the situation is that you want to create a new git repository and uploaded exsisting codes in your PC to the new repository.
-
Create a new repository in the simons observatory git hub account in git hub web site: https://github.com/simonsobs
-
Get your git repsository copy address: ex)
[email protected]:simonsobs/wire_grid_loader.git
-
This can be obtained in the Code bottom in the top page of the git repository web page. https://github.com/simonsobs/wire_grid_loader
-
There are two kinds of address;
- HTTPS address
- ssh address
The HTTPS address cannot use the ssh public key authentification and you need to type your username&password every time you want to push or pull from the remote repository.
-
-
In your PC, move to the top directory of the scripts to be uploaded to git
-
Make
README.md
echo "# <REPOSITORY NAME>" >> README.md
-
Initilize your git repository in your PC
git init git add . (including your exsited scripts) git commit -m "<COMMENT>" git remote add origin <GIT REPOSITORY ADDRESS> git push -u origin master
<GIT REPOSITORY ADDRESS>
is [email protected]:simonsobs/wire_grid_loader.git for the wire_grid_loader repository.
-
If your machine does not have git nor ssh, please install them. In a linux machine,
sudo apt install git ssh
or
sudo yum install git ssh
-
In the directory where you want to put the repository, clone the repository
git clone https://github.com/simonsobs/wire_grid_loader.git
* This will not require access authorization or user account. But, if you use the [email protected]:simonsobs/wire_grid_loader.git, you need to do account setting on your machine.
If you want to clone a specific branch <BRANCH NAME>, plase do
git clone -b <BRANCH NAME> https://github.com/simonsobs/wire_grid_loader.git
You can make tags on a specific commitment.
At a state in which you want to tag,
git tag <TAG_NAME> -m "<COMMENT>"
In this library, please use a tag name of "vX.Y". (X, Y: numbers)
Please don't forget push your tags to remote repository(below).
git push --tags
git tag -l
git tag -v <TAG_NAME>
git tag -d <TAG_NAME>
Ref. : https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
-
Generate ssh public key
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- The public key file should be
id_rsa.pub
- The public key file should be
-
Add the public key to your git account
Ref.: https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account
Ref.: https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases
Set git commands alias;
-
commit --> ci
-
checkout --> co
-
branch --> br
-
status --> st
git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st status
To ignore some specific files to be uploaded, you need to make .gitignore
file in the top directory of the repository.
Ref.: https://git-scm.com/docs/gitignore