linux:git

This is an old revision of the document!


Git Basics

Git is a complicated tool to use, if you don't use it on a very regular basis.

I prefer using Graphic interfaces that help a lot with git management like in Atom, but here is a recap of basic commands so I remember them when I need.

Git How-to

git add the.file
git commit -m "The message"
git push

Switch branch (option create)

git checkout branch_name
git checkout -b create_branch_name

When you create a new Rust project using Cargo it automatically initializes a local git repository.

To connect it with a remote repository follow the basic instructions :

git remote add origin <remote_repo_url>
git push --all origin

You will be prompted for username and password of owner of the Git distant repository.

Edit (Fall 2019) : This actually doesn't work very well, see below for proper instructions.

If you want to set all of your branches to automatically use this remote repo when you use git pull, add –set-upstream to the push:

git push --all --set-upstream origin 

This is the advised way to push to a new repo by Git Lab and works perfectly well with a Rust project.

cd existing_folder
git init //Skip if in a Rust project created with cargo, git is already initialized
git remote add origin [Remote Repository Address.git]
git add . //Not sure it's required, since the folder is already populated.
git commit -m "Initial commit" //Feel free to change the message
git push -u origin master //This is what actually pushes.

Atom has a built-in git feature that will automatically detect git repositories and has a useful GUI. To use it, your project root folder must be directly in the project tree manager. It cannot be in a sub-directory or Atom will not autodetect the git repository.

  • linux/git.1570296711.txt.gz
  • Last modified: 2020/06/01 16:35
  • (external edit)